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

Super sports ball #81

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions lib/event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class Event
attr_reader :name, :ages

def initialize(name, ages)
@name = name
@ages = ages


end

def max_age
@ages.max
end
def min_age
@ages.min
end

def average_age
ages_sum = @ages.sum.to_f
num_of_ages = @ages.count.to_f
ages_sum / num_of_ages
end

def standard_deviation_age
average_age = self.average_age

@ages.map! do |age|
(((age.to_f) - average_age.round(1))**2).round(2)
end

standard_deviation = (Math.sqrt(((ages.sum.round(1)) / 5).round(2))).round(2)
return standard_deviation
end
end
34 changes: 34 additions & 0 deletions lib/runner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require './lib/event'
require './lib/games'
# 20.times(print "-")
puts "Welcome! Tell me the year of the event you are inquiring about?"
print "> "
year = gets.chomp

new_olympics = Games.new(year)

puts "Great! Now let's add some events! Enter 'Exit' to quit."

event_input = ""
ages = []

loop do
puts "Add another event? Use 'Exit' to quit."
print "> "
event_input = gets.chomp.capitalize
if event_input == "Exit"
puts "Thanks, let's move on."
break
end
loop do
puts "I also need to know their ages, say 'Next' to enter next event."
print "> "
age_input = gets.chomp.capitalize
if age_input == "Next"
break
end
ages << age_input
end
new_event = Event.new(event_input, ages)
new_olympics.add_event(new_event)
end
18 changes: 17 additions & 1 deletion lib/standard_deviation.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
ages = [24, 30, 18, 20, 41]

# Your code here for calculating the standard deviation
ages_sum = ages.sum.to_f
num_of_ages = ages.count.to_f
average_age = ages_sum / num_of_ages

ages.map! do |age|
(((age.to_f) - average_age.round(1))**2).round(2)
end

standard_deviation = (Math.sqrt(((ages.sum.round(1)) / 5).round(2))).round(2)

p standard_deviation







# When you find the standard deviation, print it out
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 setup
@event = Event.new("Curling", [24, 30, 18, 20, 41])
end

def test_does_it_exist

assert_instance_of Event, @event
end

def test_does_event_have_attributes

assert_equal "Curling", @event.name
assert_equal [24, 30, 18, 20, 41], @event.ages
end

def test_find_max_age

assert_equal 41, @event.max_age
end

def test_find_min_age

assert_equal 18, @event.min_age
end

def test_find_average_age

assert_equal 26.6, @event.average_age
end

def test_find_standard_deviation_age

assert_equal 8.28, @event.standard_deviation_age
end

end