Question

In: Computer Science

Design and implement a program to allow a college administrator to register new students and add...

Design and implement a program to allow a college administrator to register new students and
add courses to the existing one. In addition, your program should allow the administrator to do
the following:
• Add/Remove a new student
• Add/Remove a course to/from a selected student
• Search for a student either by last name or by id.
• Search for a course either by name or by id.
• Display a selected student along with the courses s/he is registered for.
• List all registered students along with the courses each student is registered for.

Using java

Solutions

Expert Solution

/*************************************Student.java**************************/

package student7;

import java.util.ArrayList;

public class Student {

   private String id;
   private String name;
   private ArrayList<Course> courses;

   public Student() {
       this.id = "";
       this.name = "";
       this.courses = new ArrayList<>();
   }

   public Student(String id, String name) {
       super();
       this.id = id;
       this.name = name;
       this.courses = new ArrayList<>();
   }

   public String getId() {
       return id;
   }

   public void setId(String id) {
       this.id = id;
   }

   public String getName() {
       return name;
   }

   public void setName(String name) {
       this.name = name;
   }

   public void addCourse(Course course) {

       courses.add(course);
   }

  
   public ArrayList<Course> getCourses() {
       return courses;
   }

   @Override
   public String toString() {
       return "Student " + id + ", " + name + ", courses: " + courses;
   }
  
}
/*****************************Course.java******************************/

package student7;

public class Course {

   private String id;
   private String name;
  
   public Course() {
      
       this.id = "";
       this.name = "";
   }

   public Course(String id, String name) {
       super();
       this.id = id;
       this.name = name;
   }

   public String getId() {
       return id;
   }

   public void setId(String id) {
       this.id = id;
   }

   public String getName() {
       return name;
   }

   public void setName(String name) {
       this.name = name;
   }

   @Override
   public String toString() {
       return "Course "+ id + ", " + name;
   }
  
  
}
/***************************************Admin.java**********************/

package student7;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;

public class Admin {

   static ArrayList<Student> students;
   static ArrayList<Course> courses;

   public static void main(String[] args) {

       students = new ArrayList<>();
       courses = new ArrayList<>();
       Scanner scan = new Scanner(System.in);
       int choice = 0;
       do {

           menu();
           System.out.print("Please select any choice: ");
           choice = scan.nextInt();
           switch (choice) {
           case 1:
               addStudent();
               break;
           case 2:
               removeStudent();
               break;
           case 3:
               addCourse();
               break;
           case 4:
               removeCourse();
               break;
           case 5:
               searchStudentById();
               break;
           case 6:
               searchStudentByName();
               break;
           case 7:
               searchCourseById();
               break;
           case 8:
               searchCourseByName();
               break;
           case 9:
               displaySelectedStudent();
               break;
           case 10:
               displayListOfStudent();
               break;
           case 11:
               System.out.println("Thank you, Bye!");
               break;
           default:
               System.out.println("Invalid Choice!");
               break;
           }

       } while (choice != 11);
   }

   private static void addStudent() {

       Scanner scan = new Scanner(System.in);
       System.out.print("Enter Student id: ");
       String id = scan.nextLine();
       System.out.print("Enter Student name: ");
       String name = scan.nextLine();
       students.add(new Student(id, name));
   }

   private static void removeStudent() {

       Scanner scan = new Scanner(System.in);
       System.out.print("Enter Student id: ");
       String id = scan.nextLine();
       int flag = 0;
       Iterator<Student> itr = students.iterator();
       while (itr.hasNext()) {

           Student student = itr.next();
           if (student.getId().equalsIgnoreCase(id)) {

               itr.remove();
               flag = 1;
           }
       }
       if (flag == 0) {

           System.out.println("No Student found!");
       }
   }

   private static void addCourse() {

       Scanner scan = new Scanner(System.in);
       System.out.print("Enter Student id: ");
       String id = scan.nextLine();
       int flag = 0;
       for (Student student : students) {

           if (student.getId().equalsIgnoreCase(id)) {

               System.out.print("Enter Course id: ");
               String idCourse = scan.nextLine();
               System.out.print("Enter Course name: ");
               String name = scan.nextLine();
               student.addCourse(new Course(idCourse, name));
               courses.add(new Course(idCourse, name));
               flag = 1;
           }
       }
       if (flag == 0) {

           System.out.println("No Student found!");
       }

   }

   private static void removeCourse() {

       Scanner scan = new Scanner(System.in);
       System.out.print("Enter Student id: ");
       String id = scan.nextLine();
       int flag = 0;
       for (Student student : students) {

           if (student.getId().equalsIgnoreCase(id)) {

               System.out.print("Enter Course id: ");
               String idCourse = scan.nextLine();
               Iterator<Course> itr = student.getCourses().iterator();
               while (itr.hasNext()) {

                   Course course = itr.next();
                   if (course.getId().equalsIgnoreCase(idCourse)) {

                       itr.remove();
                       flag = 1;
                   }
               }
           }
       }
       if (flag == 0) {

           System.out.println("No Course found!");
       }
   }

   private static void searchStudentById() {

       Scanner scan = new Scanner(System.in);
       System.out.print("Enter Student id: ");
       String id = scan.nextLine();
       int flag = 0;
       for (Student student : students) {

           if (student.getId().equalsIgnoreCase(id)) {

               System.out.println(student.getId() + ", " + student.getName());
               flag = 1;
           }
       }
       if (flag == 0) {

           System.out.println("No Student Found by this id!");
       }
   }

   private static void searchStudentByName() {

       Scanner scan = new Scanner(System.in);
       System.out.print("Enter Student name: ");
       String name = scan.nextLine();
       int flag = 0;
       for (Student student : students) {

           if (student.getName().equalsIgnoreCase(name)) {

               System.out.println(student.getId() + ", " + student.getName());
               flag = 1;
           }
       }
       if (flag == 0) {

           System.out.println("No Student Found by this id!");
       }

   }

   private static void searchCourseById() {

       Scanner scan = new Scanner(System.in);
       System.out.print("Enter Course id: ");
       String id = scan.nextLine();
       int flag = 0;
       for (Course course : courses) {

           if (course.getId().equalsIgnoreCase(id)) {

               System.out.println(course.toString());
               flag = 1;
           }
       }
       if (flag == 0) {

           System.out.println("No Course Found!");
       }

   }

   private static void searchCourseByName() {

       Scanner scan = new Scanner(System.in);
       System.out.print("Enter Course name: ");
       String name = scan.nextLine();
       int flag = 0;
       for (Course course : courses) {

           if (course.getName().equalsIgnoreCase(name)) {

               System.out.println(course.toString());
               flag = 1;
           }
       }
       if (flag == 0) {

           System.out.println("No Course Found!");
       }
   }

   private static void displaySelectedStudent() {

       Scanner scan = new Scanner(System.in);
       System.out.print("Enter Student id: ");
       String id = scan.nextLine();
       int flag = 0;
       for (Student student : students) {

           if (student.getId().equalsIgnoreCase(id)) {

               System.out.println(student.toString());
               flag = 1;
           }
       }
       if (flag == 0) {

           System.out.println("No Student Found by this id!");
       }
   }

   private static void displayListOfStudent() {

       Scanner scan = new Scanner(System.in);
       System.out.print("Enter Course name: ");
       String name = scan.nextLine();
       int flag = 0;
       for (Student student : students) {

           for (int i = 0; i < courses.size(); i++) {

               if (student.getCourses().get(i).getName().equalsIgnoreCase(name)) {

                   System.out.println(student.toString());
               }
           }
           if (flag == 0) {

               System.out.println("No Student found!");
           }
       }

   }

   private static void menu() {

       System.out.println("1. Add a Student\n" + "2. Remove a Student\n" + "3. Add a Course to Student\n"
               + "4. Remove a Course from Student\n" + "5. Search Student by id\n" + "6. Search Student by name\n"
               + "7. Search Course by id\n" + "8. Search Course by name\n" + "9. Display a selected Student\n"
               + "10. List Student with registered Course\n" + "11. Exit");
   }
}
/***************************output*******************************/

1. Add a Student
2. Remove a Student
3. Add a Course to Student
4. Remove a Course from Student
5. Search Student by id
6. Search Student by name
7. Search Course by id
8. Search Course by name
9. Display a selected Student
10. List Student with registered Course
11. Exit
Please select any choice: 1
Enter Student id: 101
Enter Student name: Virat
1. Add a Student
2. Remove a Student
3. Add a Course to Student
4. Remove a Course from Student
5. Search Student by id
6. Search Student by name
7. Search Course by id
8. Search Course by name
9. Display a selected Student
10. List Student with registered Course
11. Exit
Please select any choice: 3
Enter Student id: 101
Enter Course id: CSE101
Enter Course name: C Programming
1. Add a Student
2. Remove a Student
3. Add a Course to Student
4. Remove a Course from Student
5. Search Student by id
6. Search Student by name
7. Search Course by id
8. Search Course by name
9. Display a selected Student
10. List Student with registered Course
11. Exit
Please select any choice: 5
Enter Student id: 101
101, Virat
1. Add a Student
2. Remove a Student
3. Add a Course to Student
4. Remove a Course from Student
5. Search Student by id
6. Search Student by name
7. Search Course by id
8. Search Course by name
9. Display a selected Student
10. List Student with registered Course
11. Exit
Please select any choice: 6
Enter Student name: Virat
101, Virat
1. Add a Student
2. Remove a Student
3. Add a Course to Student
4. Remove a Course from Student
5. Search Student by id
6. Search Student by name
7. Search Course by id
8. Search Course by name
9. Display a selected Student
10. List Student with registered Course
11. Exit
Please select any choice: 7
Enter Course id: CSE101
Course CSE101, C Programming
1. Add a Student
2. Remove a Student
3. Add a Course to Student
4. Remove a Course from Student
5. Search Student by id
6. Search Student by name
7. Search Course by id
8. Search Course by name
9. Display a selected Student
10. List Student with registered Course
11. Exit
Please select any choice: 8
Enter Course name: C Programming
Course CSE101, C Programming
1. Add a Student
2. Remove a Student
3. Add a Course to Student
4. Remove a Course from Student
5. Search Student by id
6. Search Student by name
7. Search Course by id
8. Search Course by name
9. Display a selected Student
10. List Student with registered Course
11. Exit
Please select any choice: 9
Enter Student id: 101
Student 101, Virat, courses: [Course CSE101, C Programming]
1. Add a Student
2. Remove a Student
3. Add a Course to Student
4. Remove a Course from Student
5. Search Student by id
6. Search Student by name
7. Search Course by id
8. Search Course by name
9. Display a selected Student
10. List Student with registered Course
11. Exit
Please select any choice: 10
Enter Course name: C Programming
Student 101, Virat, courses: [Course CSE101, C Programming]
No Student found!
1. Add a Student
2. Remove a Student
3. Add a Course to Student
4. Remove a Course from Student
5. Search Student by id
6. Search Student by name
7. Search Course by id
8. Search Course by name
9. Display a selected Student
10. List Student with registered Course
11. Exit
Please select any choice: 11
Thank you, Bye!

Please let me know if you have any doubt or modify the answer, Thanks :)


Related Solutions

Design and implement a Java program that creates a GUI that will allow a customer to...
Design and implement a Java program that creates a GUI that will allow a customer to order pizza and other items from a Pizza Paarlor. The customer should be able to order a variety of items which are listed below. The GUI should allow the customer (viaJavaFX UI Controls - text areas, buttons, checkbox, radio button, etc.) to input the following information: Name of the customer First Name Last Name Phone number of the customer Type of food being order...
I need to design and implement a JAVASCRIPT program that will allow us to determine the...
I need to design and implement a JAVASCRIPT program that will allow us to determine the length of time needed to pay off a credit card balance, as well as the total interest paid. The program must implement the following functions: displayWelcome This function should display the welcome message to the user explaining what the program does. calculateMinimumPayment This function calculates the minimum payment. It should take balance and minimum payment rate as arguments and return the minimum payment. So...
Design and implement a Python program which will allow two players to play the game of...
Design and implement a Python program which will allow two players to play the game of Tic-Tac-Toe in a 4x4 grid! X | O | X | O -------------- O | O | X | O -------------- X | X | O | X -------------- X | X | O | X The rules for this game is the same as the classic, 3x3, game – Each cell can hold one of the following three strings: "X", "O", or "...
Design and implement an application that can compute the weekly pay for different students at a college.
In Java Design and implement an application that can compute the weekly pay for different students at a college. Students (all with a name, major, GPA) can be undergraduate or graduate students. Undergraduate students can be volunteers to be tuto rs or teaching assistants. Graduate students can be teaching assistants or research assistants. Volunteer tuto rs are not paid anything. Undergraduate teaching assistants are paid $15 per hour and can work a maximum of 20 hours per week. Graduate teaching assistants...
A college administrator wants to survey 250 students that attend her college to see if students...
A college administrator wants to survey 250 students that attend her college to see if students are satisfied with the course offerings. Match the strategies to their corresponding sampling techniques. The administrator stands by the front door of the admissions department and asks the first 250 students who walk in. The administrator researches the ethnic make-up of the college and makes sure that the proportion of each ethnic group represented in the sample is the same as the corresponding proportion...
Overview For this program, add code to program 2 that will (potentially) allow for a discount...
Overview For this program, add code to program 2 that will (potentially) allow for a discount to be applied to the cost of the tickets to the movie theater. Basic Program Logic The program should start the same as program 2 by asking the user for the number of tickets to purchase for adult and children. The program should then ask the user if they have a discount coupon. This is a string value. A value of "Y" indicates the...
A survey of undergraduate college students at a small university was recently done by an administrator...
A survey of undergraduate college students at a small university was recently done by an administrator in charge of residential life services. A random sample of 300 students was selected from each class level (freshman, sophomore, junior, senior). Each student was asked to complete and return a short questionnaire on quality of campus residence. Some students returned the questionnaire, and some didn't. This is summarized in the table below: Class Returned Not response Total Freshman 110 190 300 Sophomore 130...
At a small liberal arts college, students can register for one to six courses. In a...
At a small liberal arts college, students can register for one to six courses. In a typical fall semester, 5% of students take one class, 26% take four classes, and 15% take six classes. a) If 77% of students take four or more classes, find the probability that a randomly selected student takes five courses. What is the probability that a randomly selected student takes three classes, if 10% take at most two classes? b) Calculate the expected value and...
PYTHON In this lab we will design a menu-based program. The program will allow users to...
PYTHON In this lab we will design a menu-based program. The program will allow users to decide if they want to convert a binary number to base 10 (decimal) or convert a decimal number to base 2 (binary). It should have four functions menu(), reverse(), base2(), and base10(). Each will be outlined in detail below. A rubric will be included at the bottom of this document. Menu() The goal of menu() is to be the function that orchestrates the flow...
Modify program 4-27 on page 219 as follows: 1) Add a new membership category for STUDENTS...
Modify program 4-27 on page 219 as follows: 1) Add a new membership category for STUDENTS with a monthly rate of $90.00. The menu should have one more choice, and the switch statement should implement one more case. 2) The input for the number of months should be validated for 1 -36 months. No charges should be displayed for incorrect number of months. Instead, an error should be displayed similar with the one for wrong menu choice. // This menu-driven...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT