-
Notifications
You must be signed in to change notification settings - Fork 0
/
directory7.rb
47 lines (39 loc) · 1.27 KB
/
directory7.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def input_students
months = [:january, :february, :march, :april, :may, :june,
:july, :august, :september, :october, :november, :december]
puts "Please enter the names and details of the students"
puts "To finish, just hit return with the name field blank"
students = []
puts "New student name?"
name = gets.chomp
while !name.empty? do
puts "#{name}'s height in cm?"
height = gets.chomp.to_f
puts "#{name}'s cohort group? (Leave blank if November)"
while true do
cohort = gets.chomp.downcase.to_sym
cohort = :november if cohort.empty?
months.include?(cohort) ? break : puts("Please enter a valid month:")
end
students << {name: name, cohort: cohort, height: height}
puts "Now we have #{students.count} students"
puts "New student name?"
name = gets.chomp
end
students
end
def print_header
puts "The students of Villains academy"
puts "-----------"
end
def print(students)
students.each_with_index { |student,index|
puts "#{index + 1}. #{student[:name]}, #{student[:cohort].capitalize} cohort, height: #{student[:height]}cm".center(80)}
end
def print_footer(names)
puts "Overall we have #{names.count} great students"
end
students = input_students
print_header
print(students)
print_footer(students)