Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maxwell Baird #75

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
75 changes: 75 additions & 0 deletions lib/event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
class Event

attr_reader :name, :ages
def initialize(event_name, ages_for_event)
@name = event_name
@ages = ages_for_event
end

def max_age
max_age_holder = 0
@ages.each do |age|

if age > max_age_holder
max_age_holder = age
end

end
max_age_holder
end

def min_age
min_age_holder = 99999999

@ages.each do |age|

if age < min_age_holder
min_age_holder = age
end

end

min_age_holder
end

def average_age
average_age_holder = 0.0

@ages.each do |age|
average_age_holder += age
end

value = average_age_holder / @ages.size
value.round(2)
end

def standard_deviation_age
step1_value = 0.0
divide_value = @ages.size
@ages.each do |value|
step1_value += value
end
step3_value = 0.0
step3_value = step1_value / divide_value

step4_array = []
@ages.each do |value|
step4_array << (value - step3_value)
end

step5_array = []
step4_array.each do |value|
step5_array << (value * value)
end

step6_sum = 0
step5_array.each do |value|
step6_sum += value
end
step7_divide = step6_sum / divide_value

total = Math.sqrt(step7_divide)
total.round(2)
end

end
30 changes: 30 additions & 0 deletions lib/games_runner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require './lib/event'
require './lib/games'

puts "What year is it?"
year = gets.chomp
game = Games.new(year)
puts "Type in the name of the event and then the ages of the players."
puts "Type quit to see a summary"
input = ''
puts "What is the name of the event? Type quit here to see the summary"
input = gets.chomp
while input != "quit" do
ages_array = []
puts "Type in the age of one player. Type in quit to create a different event"
age_input = ''
if input != 'quit'
while age_input != 'quit' do
puts "Age of a player: "
age_input = gets.chomp
if age_input != 'quit'
ages_array << age_input.to_i
end # age_input != 'quit'
end # age_input != 'quit' do
end # input != 'quit'
event = Event.new(input, ages_array)
game.add_event(event)
puts "What is the name of the next event? Type quit here to see the summary"
input = gets.chomp
end #while input != "quit" do
puts game.summary
28 changes: 28 additions & 0 deletions lib/standard_deviation.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
ages = [24, 30, 18, 20, 41]

# Your code here for calculating the standard deviation
def standard_deviation(dev_array)

step1_value = 0.0
dev_array.each do |value|
step1_value += value
end
step3_value = 0.0
step3_value = step1_value / dev_array.size

step4_array = []
dev_array.each do |value|
step4_array << (value - step3_value)
end

step5_array = []
step4_array.each do |value|
step5_array << (value * value)
end

step6_sum = 0
step5_array.each do |value|
step6_sum += value
end
step7_divide = step6_sum / dev_array.size

total = Math.sqrt(step7_divide)
puts total
end
# When you find the standard deviation, print it out
standard_deviation(ages)
41 changes: 41 additions & 0 deletions test/event_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require 'minitest/autorun'
require 'minitest/pride'
require './lib/event'

class EventTest < Minitest::Test

def test_if_event_exist
event = Event.new("Curling", [24, 30, 18, 20, 41])
assert_instance_of Event, event
end

def test_if_event_has_name
event = Event.new("Curling", [24, 30, 18, 20, 41])
assert_equal "Curling", event.name
end

def test_if_event_has_ages
event = Event.new("Curling", [24, 30, 18, 20, 41])
assert_equal [24, 30, 18, 20, 41], event.ages
end

def test_event_max_age
event = Event.new("Curling", [24, 30, 18, 20, 41])
assert_equal 41, event.max_age
end

def test_event_min_age
event = Event.new("Curling", [24, 30, 18, 20, 41])
assert_equal 18, event.min_age
end

def test_event_average_age
event = Event.new("Curling", [24, 30, 18, 20, 41])
assert_equal 26.6, event.average_age
end

def test_event_standard_deviation
event = Event.new("Curling", [24, 30, 18, 20, 41])
assert_equal 8.28, event.standard_deviation_age
end
end