Skip to content

Instantly share code, notes, and snippets.

@akcrono
akcrono / gist:68aa49e12d88e073acb0
Created August 12, 2014 17:32
register for launch academy day 2
require 'bigdecimal'
require 'bigdecimal/util'
puts 'What is the amount due?'
total = gets.chomp.to_f
puts 'What is the amount tendered?'
cash = gets.chomp.to_f
if total > cash
puts 'WARNING: Customer still owes $0.50! Exiting...'
@akcrono
akcrono / cash_register2.rb
Created August 13, 2014 15:16
chash register program for Launch Academy
require 'bigdecimal'
require 'bigdecimal/util'
values = []
puts 'What is the sale price?'
print '>'
input = gets.chomp
while input != 'done'
@akcrono
akcrono / cash_register3.rb
Created August 14, 2014 17:50
csv cash register project for Launch Academy
require 'csv'
require 'pry'
def return_sku (hash, number)
answer = hash.first(number)
return answer[-1][0]
end
@akcrono
akcrono / systemscheck1.rb
Created August 18, 2014 01:09
first systems check for Launch Academy. 3 methods returning average, max, and min scores.
def find_average scores
sum = 0.0
scores.each do |x|
sum += x
end
return sum/scores.length
end
def find_max scores
answer = 0
SELECT title, rating FROM movies ORDER BY rating LIMIT 50;
SELECT title FROM movies WHERE rating = 0 ORDER BY title;
SELECT title FROM movies WHERE synopsis LIKE '%thrilling%';
SELECT movies.title, movies.year, movies.rating FROM movies JOIN genres ON movies.genre_id = genres.id WHERE genres.name = 'Science Fiction & Fantasy' AND year BETWEEN 1980 AND 1989 ORDER BY rating DESC;
SELECT actors.name, movies.title, movies.year FROM movies
JOIN cast_members ON movies.id = cast_members.movie_id
class Card
def initialize(rank = nil, suit = nil)
if suit.nil?
@suit = ['♠', '♣', '♥', '♦'].sample
else
@suit = suit
end
if rank.nil?
srand()
@rank = rand(13)+1
class television
def initialize(make, model, type, channel = 3, volume = 5)
@make = make
@model = model
@type = type
@channel=channel
@volume=volume
end
class Card
def initialize(rank, suit)
@suit = suit
@rank = rank
end
def suit
@suit
end
class Car
def initialize(color, owner, cylinders)
@color = color
@owner = owner
@cylinders = cylinders
end
def color
@color
end
class Whiteboard
attr_accessor :contents
def initialize(contents = [])
@contents = contents
end
def erase
@contents = []
end