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

Stephanie Friend #77

Open
wants to merge 5 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
27 changes: 27 additions & 0 deletions lib/event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require_relative 'standard_deviation'
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.to_f / ages.length.to_f
end

def standard_deviation_age
standard_deviation = StandardDeviation.new(@ages)
standard_deviation.calculate_standard_deviation
end
end
38 changes: 38 additions & 0 deletions lib/print_out.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
class PrintOut

def initialize
@ages = []
end

def enter_year
puts "Enter year: "
gets.chomp
end

def enter_event_name
puts "Enter Event Name: "
gets.chomp
end

def initial_enter_age
puts "Enter Age of First Participant: "
@ages << gets.chomp.to_i
additional_enter_ages
@ages
end

def additional_enter_ages
puts "Do You Have Another Participant? Y for yes, N for no "
answer = gets.chomp.upcase
if answer == "Y"
puts "Enter Age of Next Participant: "
@ages << gets.chomp.to_i
additional_enter_ages
elsif answer == "N"
puts "Thank You For Your Input"
else
puts "Invalid Input, Please Try Again"
additional_enter_ages
end
end
end
30 changes: 27 additions & 3 deletions lib/standard_deviation.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
ages = [24, 30, 18, 20, 41]
class StandardDeviation

# Your code here for calculating the standard deviation
def initialize(numbers)
@numbers = numbers
end

# When you find the standard deviation, print it out
def calculate_standard_deviation
sum = @numbers.sum

num = @numbers.length

divide = sum.to_f / num.to_f

sub = @numbers.map { |number| number - divide }

square = sub.map { |s| s ** 2 }

sum2 = square.sum

divide2 = sum2 / num

square = Math.sqrt(divide2).round(2)

p square
end
end

standard_deviation = StandardDeviation.new([24, 30, 18, 20, 41])
standard_deviation.calculate_standard_deviation
11 changes: 11 additions & 0 deletions runner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require './lib/games'
require './lib/event'
require './lib/print_out'

print_out = PrintOut.new

game = Games.new(print_out.enter_year)

event = Event.new(print_out.enter_event_name, print_out.initial_enter_age)
game.add_event(event)
p game.summary
44 changes: 44 additions & 0 deletions test/event_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require 'minitest/autorun'
require 'minitest/pride'
require './lib/games'
require './lib/event'

class EventTest < Minitest::Test

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

assert_instance_of Event, event
end

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

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

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

assert_equal 41, event.max_age
end

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

assert_equal 18, event.min_age
end

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

assert_equal 26.6, event.average_age
end

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

assert_equal 8.28, event.standard_deviation_age
end
end