-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdirectory.rb
More file actions
130 lines (98 loc) · 2.67 KB
/
Copy pathdirectory.rb
File metadata and controls
130 lines (98 loc) · 2.67 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
def input_students
puts "Please enter the names of the students"
puts "Hit return twice to end"
puts " "
# Create an empty array
students = []
puts "Name:"
name = gets.chomp
puts "Cohort:"
cohort = gets.chomp
if cohort.empty?
cohort = "Unknown"
end
puts "Country of birth?"
birth = gets.chomp
if birth.empty?
birth = "Unknown"
end
puts "Height in cm:"
height = gets.chomp
if height.empty?
height = "Unknown"
end
#while cohort.empty? do
#puts "Cohort:"
#cohort = gets.chomp
#end
# While the name is not empty repeat the code
while !name.empty? do
# Add the student hash to the array
students << {name: name.split.map(&:capitalize).join(' '), cohort: cohort.split.map(&:capitalize).join(' '), birth: birth.split.map(&:upcase).join(' '), height: height.split.map(&:capitalize).join(' ')}
if students.count == 1
puts "We now have #{students.count} student"
elsif
puts "We now have #{students.count} students"
end
# Get another name from the user
puts " "
puts "Hit return twice to end"
puts "Name:"
name = gets.chomp
puts "Cohort:"
cohort = gets.chomp
if cohort.empty?
cohort = "Unknown"
end
end
# Return the array of students
students
end
# Create methods for the program to call
def print_header(students)
if students.count == 0
puts " "
elsif students.count == 1
puts "The students of Villains Academy"
puts "--------------------------------"
puts " "
else
puts "The students of Villains Academy"
puts "--------------------------------"
puts " "
end
end
def print(students)
students.each_with_index do |student, index|
puts "#{index + 1}. #{student[:name]} (#{student[:cohort]} Cohort) | Country of birth: #{student[:birth]} | Height: #{student[:height]}"
end
end
def print_footer(students)
if students.count == 0
puts "There are no students at Villains Academy"
elsif students.count == 1
puts " "
puts "Overall we have #{students.count} great student"
elsif
puts " "
puts "Overall we have #{students.count} great students"
end
end
# Calling the methods creates the result
students = input_students
print_header(students)
print(students)
print_footer(students)
# Exercise 1 - Indexing list - completed
# Exercise 2
# Exercise 3
# Exercise 4
# Exercise 5 - Added information - completed
# Exercise 6 - Centering - completed
# Exercise 7 - Default value for empty cohort - completed
# Exercise 8
# Exercise 9 - Removing plural for single student - completed
# Exercise 10
# Exercise 11 - Typos.rb - completed
# Exercise 12
# Extended exercise 1 - Capitalising names and cohort - completed