-
Notifications
You must be signed in to change notification settings - Fork 0
/
student2.rb
152 lines (109 loc) · 3.27 KB
/
student2.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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/ruby -w
@array_of_students = Hash.new {|hash, key| hash[key] = []}
@student_id = 0
# Define Student Class
class Student
attr_accessor :stud_id, :first_name, :last_name, :age
def toggle_questions
print "Enter First Name: "
@first_name = gets.chomp
print "Enter Last Name: "
@last_name = gets.chomp
print "Enter Age: "
@age = gets.chomp
end
end
def decision_main_menu
puts
puts "*** WELCOME TO THE MOST AWESOME ENROLLMENT SYSTEM IN THE WORLD!! ***"
puts
puts
print "Now what do you want to do? Enroll[1] or View Student Info[2] or View all students[3]? "
choice = gets.chomp
decision_enroll_view(choice)
end
def decision_enroll_view(choice)
if choice == "1"
decision_enroll
elsif choice == "2"
decision_view
elsif choice == "3"
decision_view_all
end
end
def decision_enroll
@student_id += 1
student = Student.new
student.toggle_questions
@array_of_students[@student_id] << @student_id
@array_of_students[@student_id] << student.first_name
@array_of_students[@student_id] << student.last_name
@array_of_students[@student_id] << student.age
puts "The Student has been successfully added!
\n Student ID: " + @student_id.to_s + "
\n First Name: " + @array_of_students[@student_id][1] + "
\n Last Name: " + @array_of_students[@student_id][2] + "
\n Age: " + @array_of_students[@student_id][3]
puts
puts
print "Enroll another student? [Y/N]"
choice = gets.chomp.downcase
if choice == "y"
decision_enroll
elsif choice == "n"
decision_main_menu
end
end
def decision_view
keys = @array_of_students.keys
@does_exist = false
print "Enter Student ID: "
choice = gets.chomp
keys.each { |x|
if x.to_s == choice
@does_exist = true
end
}
if @does_exist == true
puts "First Name: " + @array_of_students[choice.to_i][1]
puts "Last Name: " + @array_of_students[choice.to_i][2]
puts "Age: " + @array_of_students[choice.to_i][3]
decision_view_try_again("View another student info? [Y/N]")
else
decision_view_try_again("The Student ID does not exist yet. Try again? [Y/N]")
end
end
def decision_view_all
puts
puts
unless @array_of_students == {}
puts "*** THESE ARE THE AWESOME STUDENTS THAT YOU ENROLLED! ***"
puts
@array_of_students.each do |key, value|
puts "Student ID: " + value[0].to_s
puts "First Name: " + value[1]
puts "Last Name: " + value[2]
puts "Age: " + value[3]
puts
end
else
puts "*** YOU HAVEN'T ENROLLED AN AWESOME STUDENT YET!!! ***"
puts "/////// //// //"
puts "// // // //"
puts "///// // // //"
puts "// // // //"
puts "////// // ////"
puts puts puts puts puts
end
decision_main_menu
end
def decision_view_try_again(message)
print message
choice = gets.chomp.downcase
if choice == "y"
decision_view
elsif choice == "n"
decision_main_menu
end
end
decision_main_menu