Import Import Import Class Private Private Private Private Int Public Super This New
Import Import Import Class Private Private Private Private Int Public Super This New
ArrayList;
import java.util.List;
import java.util.Scanner;
class Course{
numberOfStudents--;
return 1;
}
}
return 0;
}
class Student{
numberOfCourses--;
return 1;
}
}
return 0;
}
class Faculty{
int id = 0;
byte choice;
String tempInput;
boolean flag;
do {
choice = input.nextByte();
input.nextLine(); // skipping \n charater left by
nextByte
switch (choice)
{
case 1:
System.out.print("Please Enter the Name of a Student: ");
tempInput = input.nextLine();
students.add(s);
// adding the object to the list
System.out.println("A Student with an ID " + id + " has
been successfully Added");
break;
case 2:
{
System.out.print("Please Enter the Name of a Faculty
Member: ");
tempInput = input.nextLine();
faculty.add(f);
// adding the faculty object to the list
System.out.println("A Faculty with an ID " + id + " has
been successfully Added");
break;
}
case 3:
{
flag = false;
if(f.getFacultyName().equals(tempInput_2))
{
f.setCoursesTeaching(tempInput);
faculty.set(i, f);
flag = true;
break;
}
}
if(flag == true) {
Course c = new Course(tempInput); //add a new
course
c.setCourseCode(Integer.toString(++id));
courses.add(c);
System.out.println("A Course with an ID " + id + "
has been successfully Added");
}
else
System.out.print("Faculty Member Not Found, Please
Try Again\n");
break;
}
int studentIndex = 0;
for( ; studentIndex < students.size(); ++studentIndex)
{
Student temp = students.get(studentIndex);
if(tempInput.equals(temp.getStudentId()))
//Student successfully found
{
flag = true;
break;
}
}
if(flag==false)
System.out.println("There is no Such Student in our
Record. Please try Again");
else
{
flag = false;
// resetting the flag to reuse it.
int courseIndex = 0;
for( ; courseIndex < courses.size(); ++courseIndex)
{
Course temp = courses.get(courseIndex);
if(tempInput_2.equals(temp.getCourseName()))
//Course successfully found
{
flag = true;
if(choice == 4)
// Add Student in course
{
// updating students and course
object
Student temp_1 =
students.get(studentIndex);
temp_1.setCoursesRegistered(tempInput_2);
students.set(studentIndex,
temp_1);
Course temp_2 =
courses.get(courseIndex);
temp_2.addStudents(tempInput);
courses.set(courseIndex,
temp_2);
else if(choice == 5)
// Remove student from course
{
Student temp_1 =
students.get(studentIndex);
temp_1.RemoveCourse(tempInput_2);
students.set(studentIndex,
temp_1);
Course temp_2 =
courses.get(courseIndex);
temp_2.RemoveStudent(tempInput);
courses.set(courseIndex,
temp_2);
if(flag == false)
System.out.println("There is no Such Course
in our Record. Please try Again");
}
break;
}
case 6:
{
flag = false;
String regCourses[] =
temp.getCoursesRegistered();
for(int i = 0; i<temp.getNumberOfCourses();
++i)
System.out.print(regCourses[i] + " ");
System.out.println("");
flag = true;
break;
}
}
if(flag == false)
System.out.print("Student Not Found, Please Try
Again" );
break;
}
case 7:
{
flag = false;
System.out.println("");
flag = true;
break;
}
}
if(flag == false)
System.out.print("Course Not Found, Please Try
Again" );
break;
}
case 8:
System.out.println("Exiting the Program. Thanks!");
break;
default:
System.out.print("\nInvalid Option. Try again");
} // switch
} // do-while
while(choice != 8);
} // main
} //class