develop #2
@@ -1,7 +1,11 @@
|
|||||||
package CourseRegistrationStarter;
|
package CourseRegistrationStarter;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
ArrayList<Student> students= new ArrayList<>();
|
||||||
// TODO:
|
// TODO:
|
||||||
Course BP = new Course("Basic Programming", "BP1404", 3);
|
Course BP = new Course("Basic Programming", "BP1404", 3);
|
||||||
Course AP = new Course("Advanced Programming", "AP1405", 2);
|
Course AP = new Course("Advanced Programming", "AP1405", 2);
|
||||||
@@ -12,7 +16,6 @@ public class Main {
|
|||||||
register.addCourseToSystem(BP);
|
register.addCourseToSystem(BP);
|
||||||
register.addCourseToSystem(AP);
|
register.addCourseToSystem(AP);
|
||||||
register.addCourseToSystem(DS);
|
register.addCourseToSystem(DS);
|
||||||
|
|
||||||
saeedJam.addCourse(AP);
|
saeedJam.addCourse(AP);
|
||||||
saeedJam.addCourse(DS);
|
saeedJam.addCourse(DS);
|
||||||
saeedJam.dropCourse(DS);
|
saeedJam.dropCourse(DS);
|
||||||
@@ -24,5 +27,84 @@ public class Main {
|
|||||||
// 5. Register the student in some courses
|
// 5. Register the student in some courses
|
||||||
// 6. Drop one course
|
// 6. Drop one course
|
||||||
// 7. Print the final registered course list
|
// 7. Print the final registered course list
|
||||||
|
int command = 100;
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
while (command != 0) {
|
||||||
|
if (command == 1) {
|
||||||
|
String courseName = "";
|
||||||
|
String courseCode = "";
|
||||||
|
int courseCapacity = 0;
|
||||||
|
System.out.println("Please enter course name: ");
|
||||||
|
courseName = scanner.nextLine();
|
||||||
|
System.out.println("Enter course code: ");
|
||||||
|
courseCode = scanner.nextLine();
|
||||||
|
System.out.println("Enter course capacity: ");
|
||||||
|
courseCapacity = scanner.nextInt();
|
||||||
|
scanner.nextLine();
|
||||||
|
register.addCourseToSystem(new Course(courseName, courseCode, courseCapacity));
|
||||||
|
System.out.println("Course added successfully.");
|
||||||
|
|
||||||
|
} else if (command == 2) {
|
||||||
|
String studentName = "";
|
||||||
|
String studentId = "";
|
||||||
|
System.out.println("Please enter student name: ");
|
||||||
|
studentName = scanner.nextLine();
|
||||||
|
System.out.println("Enter student ID: ");
|
||||||
|
studentId = scanner.nextLine();
|
||||||
|
students.add(new Student(studentName, studentId));
|
||||||
|
System.out.println("Student added successfully.");
|
||||||
|
|
||||||
|
} else if (command == 3) {
|
||||||
|
String studentId = "";
|
||||||
|
String courseCode = "";
|
||||||
|
Student studentToAdd;
|
||||||
|
System.out.println("Please enter student ID: ");
|
||||||
|
studentId = scanner.nextLine();
|
||||||
|
System.out.println("Enter course code: ");
|
||||||
|
courseCode = scanner.nextLine();
|
||||||
|
studentToAdd = null;
|
||||||
|
studentToAdd = findStudentById(students, studentId);
|
||||||
|
Course courseToAdd = register.findCourseByCode(courseCode);
|
||||||
|
studentToAdd.addCourse(courseToAdd);
|
||||||
|
System.out.println("Course "+ courseCode + " added successfuly for Student " + studentId);
|
||||||
|
|
||||||
|
} else if (command == 4) {
|
||||||
|
String studentId = "";
|
||||||
|
Student studentToShow = null;
|
||||||
|
System.out.println("Please enter student ID: ");
|
||||||
|
studentId = scanner.nextLine();
|
||||||
|
studentToShow = findStudentById(students, studentId);
|
||||||
|
studentToShow.showRegisteredCourses();
|
||||||
|
} else if (command == 5) {
|
||||||
|
String courseCode = "";
|
||||||
|
System.out.println("Enter course code: ");
|
||||||
|
courseCode = scanner.nextLine();
|
||||||
|
Course courseToShow = register.findCourseByCode(courseCode);
|
||||||
|
System.out.println(courseToShow.getCourseName() + ", Code: "
|
||||||
|
+ courseToShow.getCourseCode() + ", Capacity: " + courseToShow.getCapacity());
|
||||||
|
} else if (command == 6) {
|
||||||
|
register.showAllCourses();
|
||||||
|
}
|
||||||
|
System.out.println("----------------MENU----------------");
|
||||||
|
System.out.println("1-Add course to system");
|
||||||
|
System.out.println("2-Add student");
|
||||||
|
System.out.println("3-Add course for student");
|
||||||
|
System.out.println("4-Show student courses");
|
||||||
|
System.out.println("5-Find course by code");
|
||||||
|
System.out.println("6-Show all courses");
|
||||||
|
System.out.println("0-Exit\n");
|
||||||
|
command = scanner.nextInt();
|
||||||
|
scanner.nextLine();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Student findStudentById(ArrayList<Student> studentList, String id) {
|
||||||
|
for (Student s: studentList) {
|
||||||
|
if (s.getStudentId().equals(id)) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public class RegistrationSystem {
|
|||||||
|
|
||||||
public void showAllCourses() {
|
public void showAllCourses() {
|
||||||
for(Course c: this.courses) {
|
for(Course c: this.courses) {
|
||||||
System.out.println(c.getCourseName() + ", code: " + c.getCourseCode());
|
System.out.println(c.getCourseName() + ", code: " + c.getCourseCode() + ", capacity: " + c.getCapacity());
|
||||||
}
|
}
|
||||||
// TODO: Print all courses in the system
|
// TODO: Print all courses in the system
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user