Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

We wrote a program in class to simulate a course management system in this colle

ID: 3869681 • Letter: W

Question

We wrote a program in class to simulate a course management system in this college. It included the following classes: Name, Student, Faculty, Textbook, Classroom and Course.

Write a Demo program that allows the user to enter information at runtime to create a series of four courses with all the needed components such as course title, course number, students, faculty, textbook, and classroom. Display these courses.

Display all the courses in rooms that has a projector.

Display all the courses by a specific instructor in a specific course and then change the instructor to someone else.

Display all the courses using a specific textbook and change the book price to 100.00.

Display all the courses taken by a specific student.

The following link has all the files for the classes we did: https://github.com/ChenTheInstructor/CSE148/tree/master/TT%20Chen%20CSE148%20Lcture%204%20Classes%20and%20Objects%20KISS/src/sample1

Explanation / Answer

Hi,
1. Demo2.java

package sample1;

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

public class Demo2 {

   static ArrayList<Course> courses = new ArrayList<>();
   public static void main(String[] args) {
      
       Scanner input = new Scanner(System.in);
       Scanner input1 = new Scanner(System.in);
      
       for (int i = 0; i < 2; i++) {
          
           System.out.println("Enter Course Number:");
           String cNo = input.nextLine();
          
           System.out.println("Enter Course Title:");
           String cTitle = input.nextLine();
      
           //============= class room ====================
          
           System.out.println("Class Room Number:");
           String crNo = input.nextLine();
          
           System.out.println("Has Projector in Class Room(Y/N)?");
           String crProjector = input.nextLine();
          
           System.out.println("Class Room capacity:");
           int crCapacity = input1.nextInt();
          
           //==================== Text book ==============
           System.out.println("Text book title:");
           String txBTitle = input.nextLine();          
          
           System.out.println("Text book ISBN no:");
           String txBIsbn = input.nextLine();
          
          
           double txBPrice = 0;
           try {
               System.out.println("Text book Price:");
               txBPrice = input1.nextDouble();
           } catch (Exception e) {
               System.out.println("Enter double value");
           }
           // ============ Faculty ===========
          
           System.out.println("Faculty first Name:");
           String fName = input.nextLine();
          
           System.out.println("Faculty last Name:");
           String lName = input.nextLine();
          
           System.out.println("Faculty m Initial:");
           String fInitial = input.nextLine();
          
           System.out.println("Faculty rank:");
           String fRank = input.nextLine();
          
           double fSalary = 0;
           try {
               System.out.println("Faculty Salary:");
               fSalary = input1.nextDouble();
           } catch (Exception e) {
               System.out.println("Enter double value");
           }      
          
           //=========== students =================
          
           // no of student in course
           int sNo = 0;
           try {
               System.out.println("Enter no of students");
               sNo = input1.nextInt();
           } catch (Exception e) {
               System.out.println("Enter integer value");
           }
          
           Student[] students = new Student[sNo];
          
           // create a bunch of students
           for (int j = 0; j < sNo; j++) {
              
               System.out.println("Student first Name:");
               String sFName = input.nextLine();
              
               System.out.println("Student last Name:");
               String sLName = input.nextLine();
              
               System.out.println("Student m Initial:");
               String sMInitial = input.nextLine();
              
               Student student = null;
              
               if (sMInitial.isEmpty() || sMInitial.equals("")) {
                   student = new Student(sFName, sLName);
               } else {
                   student = new Student(sFName, sMInitial.charAt(0), sLName);
               }
              
               students[j] = student;
           }
          
           // course
           Course course = new Course(cNo, cTitle);
          
           boolean hasProjector = false;
           if (crProjector.charAt(0) == 'Y' || crProjector.charAt(0) == 'y') {
               hasProjector = true;
           }
          
           //create a classroom
           Classroom classroom = new Classroom(crNo, crCapacity, hasProjector);      
           course.setClassroom(classroom);
          
           // create a textbook
           Textbook textbook = new Textbook(txBTitle, txBIsbn, txBPrice);
           course.setTextbook(textbook);
          
           // add an instructor
           Faculty faculty = null;
           if (fInitial.isEmpty() || fInitial.equals("")) {
               faculty = new Faculty(fName, lName);
           } else {
               faculty = new Faculty(fName, lName, fInitial.charAt(0));
           }
          
           faculty.setRank(fRank);
           faculty.setSalary(fSalary);
           course.setFaculty(faculty);
                      
           // add a bunch of students in course
           course.setStudents(students);
          
           // add course in arrayList
           courses.add(course);
       }
      
       System.out.println("Display all the courses in rooms that has a projector.");
      
       for (int i = 0; i < courses.size(); i++) {
           Course c = courses.get(i);
           if (c.getClassroom().getHasProjector() == true) {
               System.out.println(c.toString());
           }
       }
      
       System.out.println("Display all the courses by a specific instructor in a specific course and then change the instructor to someone else");
       System.out.print("Enter first name of instructor:");
       String fName = input.nextLine();
      
       for (int j = 0; j < courses.size(); j++) {
           Course c = courses.get(j);
           if (c.getFaculty().getName().equals(fName)) {
               System.out.println(c.toString());
           }
       }
      
       //
       System.out.println("Display all the courses using a specific textbook and change the book price to 100.00.");
       System.out.print("Enter textbook isbn:");
       String book = input.nextLine();
      
       for (int k = 0; k < courses.size(); k++) {
           Course c = courses.get(k);
           if (c.getTextbook().getIsbn().equals(book)) {
               c.getTextbook().setPrice(100.00);
               System.out.println(c.toString());
           }
       }
      
       System.out.println("Display all the courses taken by a specific student");
       System.out.print("Enter student first name:");
       String sFName = input.nextLine();
       System.out.println();
       for (int l = 0; l < courses.size(); l++) {
           Course c = courses.get(l);
           Student[] s = c.getStudents();
          
           for (Student student : s) {
               if (student.getName().equals(sFName)) {
                   System.out.println(c.toString());
               }
           }
       }
   }
}


Let me know if any change required

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote