add menu
This commit is contained in:
@@ -1,7 +1,13 @@
|
||||
package CourseRegistrationStarter;
|
||||
import java.lang.reflect.Field ;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws NoSuchFieldException {
|
||||
// TODO:
|
||||
// 1. Create at least 3 courses
|
||||
// 2. Create 1 student
|
||||
@@ -11,20 +17,76 @@ public class Main {
|
||||
// 6. Drop one course
|
||||
// 7. Print the final registered course list
|
||||
RegistrationSystem reg = new RegistrationSystem() ;
|
||||
Course Ap = new Course("ap" , "1404" , 2 );
|
||||
reg.addCourseToSystem(Ap) ;
|
||||
Course AP = new Course("ap" , "1404" , 2 );
|
||||
reg.addCourseToSystem(AP) ;
|
||||
Course DS = new Course("DS" , "2201" , 1 );
|
||||
reg.addCourseToSystem(DS);
|
||||
Course DB = new Course("Db" , "3301" , 3 );
|
||||
reg.addCourseToSystem(DB);
|
||||
Map<String, Course> courseMap = new HashMap<>();
|
||||
courseMap.put("AP", AP);
|
||||
courseMap.put("DS", DS);
|
||||
courseMap.put("DB", DB);
|
||||
Student Ali = new Student("ali" , "402222001") ;
|
||||
Ali.addCourse(Ap) ;
|
||||
Ali.addCourse(DB) ;
|
||||
Ali.dropCourse(Ap) ;
|
||||
Ali.showRegisteredCourses();
|
||||
reg.showcapacity();
|
||||
|
||||
//test
|
||||
Scanner input = new Scanner(System.in) ;
|
||||
|
||||
int x = 0 ;
|
||||
while (x != 6 ) {
|
||||
System.out.println("menu");
|
||||
System.out.println("1) Add course ");
|
||||
System.out.println("2) drop course ");
|
||||
System.out.println("3) show registered courses");
|
||||
System.out.println("4 ) show all courses");
|
||||
System.out.println("5) Show capacities ");
|
||||
System.out.println("6) exit ");
|
||||
System.out.println("enter your choice ");
|
||||
x = input.nextInt() ;
|
||||
input.nextLine() ;
|
||||
if (x == 1 )
|
||||
{
|
||||
System.out.println("Available courses: AP - DS - DB");
|
||||
String y = input.nextLine().trim();
|
||||
Course selected = courseMap.get(y.toUpperCase());
|
||||
if (selected != null) {
|
||||
Ali.addCourse(selected);
|
||||
} else {
|
||||
System.out.println("No");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
else if (x == 2 ) {
|
||||
System.out.println("courses names : AP - DS - DB");
|
||||
String y = input.nextLine().trim();
|
||||
Course selected = courseMap.get(y.toUpperCase());
|
||||
if (selected != null) {
|
||||
Ali.addCourse(selected);
|
||||
} else {
|
||||
System.out.println("No");
|
||||
}
|
||||
|
||||
}
|
||||
else if (x == 3 ) {
|
||||
Ali.showRegisteredCourses();
|
||||
|
||||
}
|
||||
else if (x == 4 )
|
||||
{
|
||||
reg.showAllCourses();
|
||||
} else if (x == 5 ) {
|
||||
reg.showcapacity();
|
||||
|
||||
} else if (x == 6) {
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,6 +66,7 @@ public class RegistrationSystem {
|
||||
public void showcapacity(){
|
||||
for (Course item : courses)
|
||||
{
|
||||
|
||||
System.out.println(item.getCapacity());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public class Student {
|
||||
else
|
||||
{
|
||||
return false ;
|
||||
// test
|
||||
// test
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user