package lab4; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class University { private Scanner input = new Scanner(System.in); private Student stdnt = new Student(); private FacultyMember fclty = new FacultyMember(); private List stdntList = new ArrayList(); private List fcltyList = new ArrayList(); private List crsList = new ArrayList(); public void menu(){ System.out.println("\nType in the number next to the action you want to choose:" + "\n1. Show and edit the student list" + "\n2. Show and edit the faculty list" + "\n3. Show and add to a list of the available courses" + "\nType any other number to quit."); while (!input.hasNextInt()) {// checks if input is valid for an // "int" value input.nextLine();// throws away bad input System.out.println("\nThat isn't a valid number, please enter again:"); } int choice = input.nextInt(); if(choice == 1){ showStudents(); } else if(choice == 2){ showFaculty(); } else if(choice == 3){ showCourses(); } else { System.out.println("\nYou just quit the program."); System.exit(1); } } public void addStudent(){ Student adstdnt = new Student(); Address adaddrss = new Address(); System.out.println("\nType in the name of the new student: "); String addStudent = input.next(); System.out.println("\nType in " + addStudent + "'s CIN#: "); while (!input.hasNextInt()) {// checks if input is valid for an // "int" value input.nextLine();// throws away bad input System.out.println("\nThat isn't a valid number, please enter again:"); } int CIN = input.nextInt(); System.out.println("\nType in " + addStudent + "'s address number: "); while (!input.hasNextInt()) {// checks if input is valid for an // "int" value input.nextLine();// throws away bad input System.out.println("\nThat isn't a valid number, please enter again:"); } int adrssNum = input.nextInt(); System.out.println("\nType in " + addStudent + "'s street name: "); String strtNam = input.next(); System.out.println("\nType in " + addStudent + "'s city: "); String ctyNam = input.next(); System.out.println("\nType in " + addStudent + "'s state//province: "); String stPrNam = input.next(); System.out.println("\nType in " + addStudent + "'s country: "); String cntNam = input.next(); adstdnt.setName(addStudent); adstdnt.setCIN(CIN); adaddrss.setStreetNumber(adrssNum); adaddrss.setStreetName(strtNam); adaddrss.setCity(ctyNam); adaddrss.setStateProvince(stPrNam); adaddrss.setCountry(cntNam); adstdnt.setAddress(adaddrss); stdntList.add(adstdnt); System.out.println("\nYou just added " + adstdnt); showStudents(); } public void addFaculty(){ FacultyMember adfclty = new FacultyMember(); Address adaddrss = new Address(); System.out.println("\nType in the name of the new faculty member: "); String member = input.next(); System.out.println("\nType in " + member + "'s employee ID: "); while (!input.hasNextInt()) {// checks if input is valid for an // "int" value input.nextLine();// throws away bad input System.out.println("\nThat isn't a valid number, please enter again:"); } int ID = input.nextInt(); System.out.println("\nType in " + member + "'s address number: "); while (!input.hasNextInt()) {// checks if input is valid for an // "int" value input.nextLine();// throws away bad input System.out.println("\nThat isn't a valid number, please enter again:"); } int adrssNum = input.nextInt(); System.out.println("\nType in " + member + "'s street name: "); String strtNam = input.next(); System.out.println("\nType in " + member + "'s city: "); String ctyNam = input.next(); System.out.println("\nType in " + member + "'s state//province: "); String stPrNam = input.next(); System.out.println("\nType in " + member + "'s country: "); String cntNam = input.next(); adfclty.setName(member); adfclty.setID(ID); adaddrss.setStreetNumber(adrssNum); adaddrss.setStreetName(strtNam); adaddrss.setCity(ctyNam); adaddrss.setStateProvince(stPrNam); adaddrss.setCountry(cntNam); adfclty.setAddress(adaddrss); fcltyList.add(adfclty); System.out.println("\nYou just added " + adfclty); showFaculty(); } public void addCourse(){ Course adcrs = new Course(); System.out.println("\nType in the name of the new course's identifier: "); String identifier = input.next(); System.out.println("\nType in the new course's unit amount: "); while (!input.hasNextInt()) {// checks if input is valid for an // "int" value input.nextLine();// throws away bad input System.out.println("\nThat isn't a valid number, please enter again: "); } int units = input.nextInt(); adcrs.setIdentifier(identifier); adcrs.setUnits(units); crsList.add(adcrs); System.out.println("\nYou just added " + adcrs); showCourses(); } public void addStudentCourse(String adStdCrs){ Course adstdntcrs = new Course(); System.out.println("\nType in the identifier of the following courses you would like to add to " + adStdCrs + "'s curriculum,\n" + "or type anything but an identifier to return to the list of students:\n" + crsList); String addedCourse = input.next(); int valueIndex = -1; for (int a = 0; a <= crsList.size()-1; a++) { if(crsList.get(a).getIdentifier().contains(addedCourse)){//checks for the attack you want to delete valueIndex = a; } } if(valueIndex == -1){//to make sure you don't crash the program by entering an attack that doesn't exist showStudentCourses(); } else{ adstdntcrs.setIdentifier(crsList.get(valueIndex).getIdentifier()); adstdntcrs.setUnits(crsList.get(valueIndex).getUnits()); adstdntcrs.setPerson(adStdCrs); stdnt.addCourse(adstdntcrs); System.out.println("\nYou just added " + adstdntcrs); showStudentCourses(); } showStudentCourses(); } public void addFacultyCourse(String adFtyCrs){ Course adfcltycrs = new Course(); System.out.println("\nType in the identifier of the following courses you would like to add to " + adFtyCrs + "'s teaching schedule,\n" + "or type anything but an identifier to return to the list of faculty:\n" + crsList); String addedCourse = input.next(); int valueIndex = -1; for (int a = 0; a <= crsList.size()-1; a++) { if(crsList.get(a).getIdentifier().contains(addedCourse)){//checks for the attack you want to delete valueIndex = a; } } if(valueIndex == -1){//to make sure you don't crash the program by entering an attack that doesn't exist showFacultyCourses(); } else{ adfcltycrs.setIdentifier(crsList.get(valueIndex).getIdentifier()); adfcltycrs.setUnits(crsList.get(valueIndex).getUnits()); adfcltycrs.setPerson(adFtyCrs); fclty.addCourse(adfcltycrs); System.out.println("\nYou just added " + adfcltycrs); showFacultyCourses(); } showFacultyCourses(); } public void showStudents(){ int choices; if (stdntList.size() == 0){ System.out.println("\nThere are currently no students. Would you like to add some?:" + "\n1. Yes" + "\nType any other number to return to the menu"); while (!input.hasNextInt()) {// checks if input is valid for an // "int" value input.nextLine();// throws away bad input System.out.println("\nThat isn't a valid number, please enter again:"); } choices = input.nextInt(); if(choices == 1){ addStudent(); } else{ menu(); } } else{ System.out.println("\nCurrent list of students: \n" + stdntList + "\nWhat would you like to do with this list?" + "\n1. Add a student" + "\n2. Drop a student" + "\n3. Show and edit the student's course curriculum" + "\nType any other number to return to the menu"); while (!input.hasNextInt()) {// checks if input is valid for an // "int" value input.nextLine();// throws away bad input System.out.println("\nThat isn't a valid number, please enter again:"); } choices = input.nextInt(); if (choices == 1){ addStudent(); } else if (choices == 2){ dropStudent(); } else if (choices == 3){ showStudentCourses(); } else{ menu(); } } } public void showFaculty(){ int choices; if (fcltyList.size() == 0){ System.out.println("\nThere are currently no faculty members. Would you like to add some?:" + "\n1. Yes" + "\nType any other number to return to the menu"); while (!input.hasNextInt()) {// checks if input is valid for an // "int" value input.nextLine();// throws away bad input System.out.println("\nThat isn't a valid number, please enter again:"); } choices = input.nextInt(); if(choices == 1){ addFaculty(); } else{ menu(); } } else{ System.out.println("\nCurrent list of faculty: " + fcltyList + "\nWhat would you like to do with this list?" + "\n1. Add a faculty member" + "\n2. Drop a faculty member" + "\n3. Show and edit the faculty member's teaching schedule" + "\nType any other number to return to the menu"); while (!input.hasNextInt()) {// checks if input is valid for an // "int" value input.nextLine();// throws away bad input System.out.println("\nThat isn't a valid number, please enter again:"); } choices = input.nextInt(); if (choices == 1){ addFaculty(); } else if (choices == 2){ dropFaculty(); } else if (choices == 3){ showFacultyCourses(); } else{ menu(); } } } public void showCourses(){ int choices; if (crsList.size() == 0){ System.out.println("\nThere are currently no available courses. Would you like to add some?:" + "\n1. Yes" + "\nType any other number to return to the menu"); while (!input.hasNextInt()) {// checks if input is valid for an // "int" value input.nextLine();// throws away bad input System.out.println("\nThat isn't a valid number, please enter again:"); } choices = input.nextInt(); if(choices == 1){ addCourse(); } else{ menu(); } } else{ System.out.println("\nCurrent list of Courses: " + crsList + "\nWould you like to add a course?" + "\n1. Yes" + "\nType any other number to return to the menu"); while (!input.hasNextInt()) {// checks if input is valid for an // "int" value input.nextLine();// throws away bad input System.out.println("\nThat isn't a valid number, please enter again:"); } choices = input.nextInt(); if (choices == 1){ addCourse(); } else{ menu(); } } } public void showStudentCourses(){ Student stdntcrs = new Student(); System.out.println("\nType in the name of the student from above you'd like to see the curriculum of, " + "\nor just type anything but a student's name to return to the list of students:"); String studentName = input.next(); int valueIndex = -1; for (int a = 0; a <= stdntList.size()-1; a++) { if(stdntList.get(a).getName().contains(studentName)){//checks for the attack you want to delete valueIndex = a; } } if(valueIndex == -1){ showStudents(); } else{ stdntcrs.setName(stdntList.get(valueIndex).getName()); System.out.println(stdntcrs.getName() + "'s curriculum:\n"); for(int a = 0; a <= stdnt.getCourseSchedule().size()-1; a++){ if(stdnt.getCourseSchedule().get(a).getPerson().contains(stdntcrs.getName())){ System.out.println(stdnt.getCourseSchedule().get(a)); } } System.out.println("\nWhat would you like to do to this curriculum?:" + "\n1. Add a course to the curriculum" + "\n2. Drop a course from the curriculum" + "\nType any other number to return to the list of students"); while (!input.hasNextInt()) {// checks if input is valid for an // "int" value input.nextLine();// throws away bad input System.out.println("\nThat isn't a valid number, please enter again:"); } int choices = input.nextInt(); if(choices == 1){ addStudentCourse(stdntcrs.getName()); } else if(choices == 2){ dropStudentCourse(stdntcrs.getName()); } else{ showStudents(); } } } public void showFacultyCourses(){ FacultyMember fcltycrs = new FacultyMember(); System.out.println("\nType in the name of the faculty member from above you'd like to see the teaching schedule of, " + "\nor type in anything but a faculty member name to return to the list of faculty:"); String facultyName = input.next(); int valueIndex = -1; for (int a = 0; a <= fcltyList.size()-1; a++) { if(fcltyList.get(a).getName().contains(facultyName)){//checks for the attack you want to delete valueIndex = a; } } if(valueIndex == -1){ showFaculty(); } else{ fcltycrs.setName(fcltyList.get(valueIndex).getName()); System.out.println(fcltycrs.getName() + "'s teaching schedule:\n"); for(int a = 0; a <= fclty.getTeachingSchedule().size()-1; a++){ if(fclty.getTeachingSchedule().get(a).getPerson().contains(fcltycrs.getName())){ valueIndex = a; System.out.println(fclty.getTeachingSchedule().get(a)); } } System.out.println("\nWhat would you like to do to this schedule?:" + "\n1. Add a course to the schedule" + "\n2. Drop a course from the schedule" + "\nType any other number to return to the list of faculty"); while (!input.hasNextInt()) {// checks if input is valid for an // "int" value input.nextLine();// throws away bad input System.out.println("\nThat isn't a valid number, please enter again:"); } int choices = input.nextInt(); if(choices == 1){ addFacultyCourse(fcltycrs.getName()); } else if(choices == 2){ dropFacultyCourse(fcltycrs.getName()); } else{ showFaculty(); } } } public void dropStudent(){ Student drpStdnt = new Student(); System.out.println("\nType in the name of one of the above students you want to drop, " + "\nor type in anything but a student's name to return to the list of students:"); String studentName = input.next(); int valueIndex = -1; for (int a = 0; a <= stdntList.size()-1; a++) { if(stdntList.get(a).getName().contains(studentName)){//checks for the attack you want to delete valueIndex = a; } } if(valueIndex == -1){ showStudents(); } else{ drpStdnt.setName(stdntList.get(valueIndex).getName()); stdntList.remove(valueIndex); System.out.println(drpStdnt.getName() + " was just dropped."); for (int a = 0; a <= stdnt.getCourseSchedule().size()-1; a++){ if(stdnt.getCourseSchedule().get(a).getPerson().contains(stdnt.getName())){ System.out.println(stdnt.getCourseSchedule().get(a) + " is being dropped."); stdnt.dropCourse(a); } } showStudents(); } } public void dropFaculty(){ FacultyMember drpFclty = new FacultyMember(); System.out.println("\nType in the name of one of the above faculty you want to drop, " + "\nor just type anything but a faculty member's name to return to the list of faculty:"); String facultyName = input.next(); int valueIndex = -1; for (int a = 0; a <= fcltyList.size()-1; a++) { if(fcltyList.get(a).getName().contains(facultyName)){//checks for the attack you want to delete valueIndex = a; } } if(valueIndex == -1){ showFaculty(); } else{ drpFclty.setName(fcltyList.get(valueIndex).getName()); fcltyList.remove(valueIndex); System.out.println(drpFclty.getName() + " was just dropped."); for (int a = 0; a <= fclty.getTeachingSchedule().size()-1; a++){ if(fclty.getTeachingSchedule().get(a).getPerson().contains(drpFclty.getName())){ System.out.println(fclty.getTeachingSchedule().get(a) + " is being dropped."); fclty.dropCourse(a); } } showFaculty(); } } public void dropStudentCourse(String drpStdCrs){ System.out.println("\nType in the course identifier of the course you want to drop from " + drpStdCrs + "'s curriculum," + "\nor type in anything but a course identifier to go back to the list of students:"); String dropCourse = input.next(); int valueIndex = -1; for (int a = 0; a <= stdnt.getCourseSchedule().size()-1; a++){ if(stdnt.getCourseSchedule().get(a).getPerson().contains(drpStdCrs)){ if(stdnt.getCourseSchedule().get(a).getIdentifier().contains(dropCourse)){ valueIndex = a; System.out.println(stdnt.getCourseSchedule().get(a) + " was dropped from " + drpStdCrs + "'s curriculum."); stdnt.dropCourse(valueIndex); } } } if(valueIndex == -1){ showStudents(); } else{ System.out.println("\nReturning to list of students."); showStudents(); } } public void dropFacultyCourse(String drpFtyCrs){ System.out.println("\nType in the course identifier of the course you want to drop from " + drpFtyCrs + "'s teaching schedule," + "\nor type in anything but a course identifier to go back to the list of faculty:"); String dropCourse = input.next(); int valueIndex = -1; for (int a = 0; a <= fclty.getTeachingSchedule().size(); a++){ if(fclty.getTeachingSchedule().get(a).getPerson().contains(drpFtyCrs)){ if(fclty.getTeachingSchedule().get(a).getIdentifier().contains(dropCourse)){ valueIndex = a; System.out.println(fclty.getTeachingSchedule().get(a) + " was dropped from " + drpFtyCrs + "'s curriculum."); fclty.dropCourse(valueIndex); } } } if(valueIndex == -1){ showFaculty(); } else{ System.out.println("\nReturning to list of faculty."); showFaculty(); } } public String toString(){ return ""; } }