-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenu.java
executable file
·173 lines (159 loc) · 5.38 KB
/
Menu.java
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import java.util.ArrayList;
import java.util.Scanner;
class Menu {
static Scanner s = new Scanner(System.in);
// return the college
// part of menu
// return chosen College class, think of changeing to return only index
protected static College change_collge(ArrayList<College> colleges) {
int i, len = colleges.size();
String name;
if (len == 0) {
System.out.println("Create college first");
return Menu.add_college(colleges);
}
while (true) {
System.out.printf("College name or index ('back' to go back): ");
s.hasNext();
if (s.hasNextInt()) {
i = s.nextInt();
s.nextLine();
if (i > -1 && i < len)
return colleges.get(i);
else System.out.format("Index out of range (%d) !", len);
}
else {
name = s.nextLine();
if (name.equals("back"))
return null;
for (College c : colleges) {
if (c.get_clg_name().equals(name))
return c;
}
System.out.println("College name not found !");
}
}
}
protected static College add_college(ArrayList<College> colleges) {
College college;
String name;
//s.nextLine();
System.out.print("Enter college name ('back' to go back): ");
name = s.nextLine();
if (name.equals("back"))
return null;
colleges.add(college = new College(name));
return college;
}
protected static void add_department(College college) {
String name;
if (college == null) return;
System.out.print("Enter department name ('back' to go back): ");
name = s.nextLine();
if (name.equals("back"))
return;
college.add_department(new Department(name));
}
protected static void add_lecturer(College college) {
String name;
int hourly;
if (college == null) return;
//s.nextLine();
System.out.print("Enter lecturer name ('back' to go back): ");
if ((name = s.nextLine()).equals("back"))
return;
System.out.println("Enter lecturer hourly wage: ");
while (s.hasNext()) {
if (s.hasNextInt()) {
hourly = s.nextInt();
s.nextLine();
if (hourly < 0)
System.out.println("Hourly wage has to be above -1");
else {
college.add_lect(new Lecturer(name, hourly));
return;
}
}
}
}
protected static void asgn_lect_to_dep(College college) {
String name;
Lecturer lect;
if (college == null) return;
//s.nextLine();
System.out.print("Enter lecturer name ('back' to go back): ");
if ((name = s.nextLine()).equals("back"))
return;
if ((lect = college.find_lect(name)) == null) {
System.out.print("Name not found");
return;
}
//s.nextLine();
System.out.print("Enter department name ('back' to go back): ");
if ((name = s.nextLine()).equals("back"))
return;
college.assign_lect_or_stn(lect, name);
}
protected static void add_student_dep(College college) {
String name;
Student stn;
int id = -1;
if (college == null) return;
//s.nextLine();
System.out.print("Enter student name ('back' to go back): ");
if ((name = s.nextLine()).equals("back"))
return;
System.out.print("Enter student ID: ");
while (s.hasNext()) {
if (s.hasNextInt()) {
id = s.nextInt();
s.nextLine();
if (id < 0)
System.out.println("ID cant be negative number");
else
break;
}
}
college.add_stn(stn = new Student(name, id));
//s.nextLine();
System.out.print("Enter department name ('back' to go back): ");
if ((name = s.nextLine()).equals("back"))
return;
college.assign_lect_or_stn(stn, name);
}
protected static void show_dep_stns(College college) {
String name;
Department dep;
if (college == null) return;
//s.nextLine();
System.out.print("Enter department name ('back' to go back): ");
if ((name = s.nextLine()).equals("back"))
return;
if ((dep = college.find_dep(name)) == null)
return;
dep.get_dep_stns();
}
protected static void biggest_dep(College college) {
Department dep;
if (college == null) return;
if ((dep = college.biggest_dep_by_stn()) == null)
return;
System.out.println(dep.toString());
dep.get_dep_stns();
}
/*
interface mFunc {
// Method that takes a "method" as argument
static void funcRun(Runnable toRun, ArrayList<College> colleges) {
}
/*
static mFunc[] menu = new mFunc[] {
new mFunc() { public void funcRun() { add_department(Menu.change_collge(c1)); } }
};
*/
/*
static Example ex = new Example {
exampleMethod(Menu_college::add_department, ); // prints "Hello"
}
*/
}