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

In the project, you will develop four classes called School , Instructor , Cours

ID: 3828781 • Letter: I

Question

In the project, you will develop four classes called School, Instructor, Course, and Student to store instructors, courses, and student information of a school. Based on the sample input data and sample run, you should identify instance variables and methods of each class. If it’s necessary, you can add more classes for the project.

Sample Input Files

The following sample data files, C:\tmp\test1.txt and C:\tmp\test2.txt, are used for the sample run below. In the case of C:\tmp\test1.txt, the first line (= 4) indicates the number of instructors in the school. The information includes the instructor’s unique employee number, name, email, and phone number. Note that each field of a line is delimited by comma symbol (,). There’s no blank space around the comma symbol and at the end of each line.

After the instructor’s data, the following number 3 indicates the number of courses in the school. The course data includes the unique course number, course title, instructor’s number, and class location. After the course data, there is the student information (= 3 in the example). Each student information indicates the student’s unique ID, name, course enrolled, final score, and letter grade.

This is a sample file, C:\tmp\test1.txt

This is another sample file, C:\tmp\test2.txt

Sample Demo Program
The following presents a sample demo program called SchoolDemo.java.

Student student1;
System.out.println("===== Read Data 1 ====="); SCD.readData("C:\tmp\test1.txt");
System.out.println(" ===== School Info 1 ====="); SCD.schoolInfo();
System.out.println("===== Read Data 2 ====="); SCD.readData("C:\tmp\test2.txt");
System.out.println(" ===== School Info 2 ====="); SCD.schoolInfo();
SCD.addInstructor(700, "E. Tao", "tao@csumb.edu", "777-777-1234"); SCD.addCourse(300, "CST300 – ProSem", 700, "BIT110"); SCD.addCourse(231, "CST231 – Intro C++", 100, "BIT104"); System.out.println(" ===== Failed Course Addition ====="); SCD.addCourse(306, "CST306 – GUI Dev", 250, "BIT120"); SCD.addCourse(499, "CST499 – iOS Dev", 150, "BIT104"); System.out.println(" ===== Detailed Course Info ====="); SCD.courseInfo(306);
course1 = SCD.getCourse(205);
course1.updateLocation("Library 104");
System.out.println(" ===== Detailed Course Info 2 ====="); SCD.courseInfo(205);
System.out.println(" ===== Detailed Course Info 3 ====="); SCD.courseInfo();
SCD.deleteCourse(231);
SCD.deleteCourse(336);
SCD.deleteCourse(338);
System.out.println(" ===== Detailed Course Info 4 ====="); SCD.courseInfo();
SCD.addStudent(5555, "Chris Watson", 205, 85.50, "B"); System.out.println(" ===== Detailed Course Info 5 ====="); SCD.courseInfo(205);
student1 = SCD.getStudentInfo(7777);
System.out.println(" ===== Detailed Student Info ====="); System.out.println(student1);
SCD.graduateStudent(7777);
System.out.println(" ===== Detailed Student Info 2 ====="); System.out.println(SCD.getStudentInfo(7777)); SCD.graduateStudent(5555);
System.out.println(" ===== Detailed Course Info 6 ====="); SCD.courseInfo(205);
SCD.graduateStudent(5555);
System.out.println(" ===== Good Job! Bye! =====");
}
}

A sample run of your program should look like below.

===== Read Data 2 =====
Instructor addition failed – Employee number already used. Student info addition failed – Student ID number already used. Student info addition failed – Non-existing course number. Done.
===== School Info 2 =====
School Name: SCD
Instructor Information
Y. Byun
S. Narayanan
M. Lara
S. Bude
G. Bruns
Course Information
CST338 - Software Design
CST205 - Multimedia Design and Programming
CST306 - Game Engine Programming
CST336 - Internet Programming
Student Information
Alice Otter: CST338 - Software Design
Bob Otter: CST205 - Multimedia Design and Programming
Alice Otter: CST306 - Game Engine Programming
Alice Otter: CST205 - Multimedia Design and Programming
John Doe: CST338 - Software Design
===== Failed Course Addition =====
Course addition failed – Course number already used.
Course addition failed – Non-existing instructor.
===== Detailed Course Info =====
Course Number: 306
Instructor: Y. Byun
Course Title: CST306 - Game Engine Programming
Room: BIT 104
Total Enrolled: 1
Course Average: 98.00
===== Detailed Course Info 2 =====
Course Number: 205
Instructor: S. Narayanan
Course Title: CST205 - Multimedia Design and Programming Room: Library 104
CST338 Page 5 of 6 Project 1
Total Enrolled: 2
Course Average: 73.00
===== Detailed Course Info 3 =====
Number of Courses: 6
338: 2 enrolled
205: 2 enrolled
336: 0 enrolled
306: 1 enrolled
300: 0 enrolled
231: 0 enrolled
Course deletion failed – Enrolled student(s) in the class ===== Detailed Course Info 4 =====
Number of Courses: 4
338: 2 enrolled
205: 2 enrolled
306: 1 enrolled
300: 0 enrolled
===== Detailed Course Info 5 =====
Course Number: 205
Instructor: S. Narayanan
Course Title: CST205 - Multimedia Design and Programming Room: Library 104
Total Enrolled: 3

Some comments for the project 1.

For the project, you can assume that the input data file has always a correct format. For instance, you don’t need to check if the email address in the file is valid or not.

To process the input data with the comma symbol (,) delimiter, StringTokenizer class may be useful.

At the deleteCourse() method, a course should not be deleted if there’s student(s) enrolled in the course.

For the graduateStudent() method, all courses the student enrolled should be removed.

Explanation / Answer

instructor.java:


public class Instructor {
   private int empNo;
   private String name, email, phone;
   public Instructor(int empNo, String name, String email, String phone) {
       this.empNo = empNo;
       this.name = name;
       this.email = email;
       this.phone = phone;
   }
   /**
   * @return the empNo
   */
   public int getEmpNo() {
       return empNo;
   }
   /**
   * @param empNo the empNo to set
   */
   public void setEmpNo(int empNo) {
       this.empNo = empNo;
   }
   /**
   * @return the name
   */
   public String getName() {
       return name;
   }
   /**
   * @param name the name to set
   */
   public void setName(String name) {
       this.name = name;
   }
   /**
   * @return the email
   */
   public String getEmail() {
       return email;
   }
   /**
   * @param email the email to set
   */
   public void setEmail(String email) {
       this.email = email;
   }
   /**
   * @return the phone
   */
   public String getPhone() {
       return phone;
   }
   /**
   * @param phone the phone to set
   */
   public void setPhone(String phone) {
       this.phone = phone;
   }
  
  
}



Course.java:

public class Course {
   private int courseNo;
   private String title, classLocation;
   private int instructorId;
   public Course(int courseNo, String title, String classLocation,
           int instructorId) {
       this.courseNo = courseNo;
       this.title = title;
       this.classLocation = classLocation;
       this.instructorId = instructorId;
   }
   /**
   * @return the courseNo
   */
   public int getCourseNo() {
       return courseNo;
   }
   /**
   * @param courseNo the courseNo to set
   */
   public void setCourseNo(int courseNo) {
       this.courseNo = courseNo;
   }
   /**
   * @return the title
   */
   public String getTitle() {
       return title;
   }
   /**
   * @param title the title to set
   */
   public void setTitle(String title) {
       this.title = title;
   }
   /**
   * @return the classLocation
   */
   public String getClassLocation() {
       return classLocation;
   }
   /**
   * @param classLocation the classLocation to set
   */
   public void setClassLocation(String classLocation) {
       this.classLocation = classLocation;
   }
   /**
   * @return the instructorId
   */
   public int getInstructorId() {
       return instructorId;
   }
   /**
   * @param instructorId the instructorId to set
   */
   public void setInstructorId(int instructorId) {
       this.instructorId = instructorId;
   }
   public void updateLocation(String location) {
       classLocation = location;
   }
  
  
}



Stduent.java:

public class Student {

   private int id, courseEnrolled;
   private String name;
   private double score;
   private String grade;

   public Student(int id, int courseEnrolled, String name, double score,
           String grade) {
       this.id = id;
       this.courseEnrolled = courseEnrolled;
       this.name = name;
       this.score = score;
       this.grade = grade;
   }

   /**
   * @return the id
   */
   public int getId() {
       return id;
   }

   /**
   * @param id
   * the id to set
   */
   public void setId(int id) {
       this.id = id;
   }

   /**
   * @return the courseEnrolled
   */
   public int getCourseEnrolled() {
       return courseEnrolled;
   }

   /**
   * @param courseEnrolled
   * the courseEnrolled to set
   */
   public void setCourseEnrolled(int courseEnrolled) {
       this.courseEnrolled = courseEnrolled;
   }

   /**
   * @return the name
   */
   public String getName() {
       return name;
   }

   /**
   * @param name
   * the name to set
   */
   public void setName(String name) {
       this.name = name;
   }

   /**
   * @return the score
   */
   public double getScore() {
       return score;
   }

   /**
   * @param score
   * the score to set
   */
   public void setScore(double score) {
       this.score = score;
   }

   /**
   * @return the grade
   */
   public String getGrade() {
       return grade;
   }

   /**
   * @param grade
   * the grade to set
   */
   public void setGrade(String grade) {
       this.grade = grade;
   }

   public String toString() {
       String s = "Student Number: " + id;
       s += " Name: " + name;
       s += " Courses Enrolled: ";
       s += " " + courseEnrolled + ": " + score + "(" + grade + ")";

       return s;

   }

   public void graduate() {
       courseEnrolled = 0;      
   }
}


School.java:

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;


public class School {
   private String name;
  
   ArrayList<Student> students = new ArrayList<>();
   ArrayList<Course> courses = new ArrayList<>();
   ArrayList<Instructor> instructors = new ArrayList<>();
  
   School(String n) {
       name = n;
   }
   public void readData(String file) throws IOException {
       BufferedReader reader = new BufferedReader(new FileReader(file));
       int noOfInstructors = Integer.parseInt(reader.readLine());
       for(int i=0; i< noOfInstructors; i++) {
           String line = reader.readLine();
           String tokens[] = line.split(",");
           addInstructor(Integer.parseInt(tokens[0]), tokens[1], tokens[2], tokens[3]);
       }

       int noOfCourses = Integer.parseInt(reader.readLine());
       for(int i=0; i< noOfCourses; i++) {
           String line = reader.readLine();
           String tokens[] = line.split(",");
           addCourse(Integer.parseInt(tokens[0]), tokens[1], Integer.parseInt(tokens[2]), tokens[3]);
       }

       int noOfStudents = Integer.parseInt(reader.readLine());
       for(int i=0; i< noOfStudents; i++) {
           String line = reader.readLine();
           String tokens[] = line.split(",");
           addStudent(Integer.parseInt(tokens[0]), tokens[1], Integer.parseInt(tokens[2]), Double.parseDouble(tokens[3]), tokens[4]);
       }
      
       reader.close();
   }
  
   public void schoolInfo() {
       System.out.println("School Name: " + name);
       System.out.println("Instructor Information");
       for(Instructor i: instructors) {
           System.out.println(i.getName());
       }
       System.out.println("Course Information");
       for(Course i: courses) {
           System.out.println(i.getTitle());
       }
       System.out.println("Student Information");
       for(Student i: students) {
           System.out.println(i.getName() + ":" + getCourse(i.getCourseEnrolled()).getTitle());
       }
   }

   public Course getCourse(int id) {
       Course r = null;
       for(Course c: courses) {
           if(c.getCourseNo()== id)
               r = c;
       }
       return r;
   }

   public Instructor getInstructor(int id) {
       Instructor r = null;
       for(Instructor c: instructors) {
           if(c.getEmpNo()== id)
               r = c;
       }
       return r;
   }
  
   public Student getStudent(int id) {
       Student r = null;
       for(Student c: students) {
           if(c.getId()== id)
               r = c;
       }
       return r;
   }
  
   public void addInstructor(int id, String name, String email, String phone) {
       if(getInstructor(id) != null) {
           System.out.println("Instructor Addition Failed - InstructorId Exists");
       } else
           instructors.add(new Instructor(id, name, email, phone));
   }
  
   public void addCourse(int courseId, String name, int instructorId, String loc) {
       if(getInstructor(instructorId) != null) {
           if(getCourse(courseId) != null) {
               System.out.println("Course Addition Failed - CourseId Exists");
           } else {
               courses.add(new Course(courseId, name, loc, instructorId));
           }
       } else {
           System.out.println("Course Addition Failed - Non-exisiting Instructor");
       }
      
   }
  
   public void addStudent(int id, String name, int courseId, double score, String grade) {
       if(getStudent(id) != null)
           System.out.println("Student Addition Failed - StudentId Exists");
       else {
           if(getCourse(courseId) != null) {
               students.add(new Student(id, courseId, name, score, grade));
           } else {
               System.out.println("Student Addition Failed - Non-exisiting Course");
           }
       }
      
   }
   public void courseInfo(int courseId) {
       Course c = getCourse(courseId);
       if(c != null) {
           System.out.println("Course Number: " + c.getCourseNo());
           System.out.println("Instructor: " + getInstructor(c.getInstructorId()).getName());
           System.out.println("Course Title: " + c.getTitle());
           System.out.println("Room: " + c.getClassLocation());
          
           int noOfEnrolled = 0;
           int totalScore = 0;
           for(Student s: students) {
               if(s.getCourseEnrolled()==courseId) {
                   noOfEnrolled++;
                   totalScore += s.getScore();
               }
           }
           System.out.println("Total Enrolled: " + noOfEnrolled);
           if(noOfEnrolled != 0)
               System.out.println("Course Avergae: " + totalScore/noOfEnrolled);
       } else {
           System.out.println("No Course found");
       }
      
   }
  
   public void courseInfo() {
       System.out.println("Number of Courses: " + courses.size());
       for(Course c: courses) {
           int enrolled = 0;
           for(Student s: students) {
               if(s.getCourseEnrolled()==c.getCourseNo()) {
                   enrolled++;
               }
           }
           System.out.println(c.getCourseNo() + ": " + enrolled + " enrolled");
       }
      
   }
   public void deleteCourse(int id) {
       boolean enrolled = false;
       for(Student s: students) {
           if(s.getCourseEnrolled()==id) {
               enrolled = true;
           }
       }
       if(enrolled) {
           System.out.println("Course Deletion Failed - Enrolled student(s) in the class");
       } else {
           courses.remove(getCourse(id));
           System.out.println("Course Deletion Successful");
       }
      
   }
   public Student getStudentInfo(int id) {
       return getStudent(id);
   }
   public void graduateStudent(int id) {
       Student s = getStudent(id);
       if(s != null) {
           s.graduate();
       }
   }
}


Driver.java:

import java.io.IOException;

public class Driver {
   public static void main(String args[]) throws IOException {
       School SCD = new School("SCD");

       Course course1;
       Student student1;
       System.out.println("===== Read Data 1 =====");
       SCD.readData("C:\Users\ykgupta\Desktop\Learning\JavaWS\Chegg\test1.txt");
       System.out.println(" ===== School Info 1 =====");
       SCD.schoolInfo();
       System.out.println("===== Read Data 2 =====");
       SCD.readData("C:\Users\ykgupta\Desktop\Learning\JavaWS\Chegg\test2.txt");
       System.out.println(" ===== School Info 2 =====");
       SCD.schoolInfo();
       SCD.addInstructor(700, "E. Tao", "tao@csumb.edu", "777-777-1234");
       SCD.addCourse(300, "CST300 – ProSem", 700, "BIT110");
       SCD.addCourse(231, "CST231 – Intro C++", 100, "BIT104");
       System.out.println(" ===== Failed Course Addition =====");
       SCD.addCourse(306, "CST306 – GUI Dev", 250, "BIT120");
       SCD.addCourse(499, "CST499 – iOS Dev", 150, "BIT104");
       System.out.println(" ===== Detailed Course Info =====");
       SCD.courseInfo(306);
       course1 = SCD.getCourse(205);
       course1.updateLocation("Library 104");
       System.out.println(" ===== Detailed Course Info 2 =====");
       SCD.courseInfo(205);
       System.out.println(" ===== Detailed Course Info 3 =====");
       SCD.courseInfo();
       SCD.deleteCourse(231);
       SCD.deleteCourse(336);
       SCD.deleteCourse(338);
       System.out.println(" ===== Detailed Course Info 4 =====");
       SCD.courseInfo();
       SCD.addStudent(5555, "Chris Watson", 205, 85.50, "B");
       System.out.println(" ===== Detailed Course Info 5 =====");
       SCD.courseInfo(205);
       student1 = SCD.getStudentInfo(7777);
       System.out.println(" ===== Detailed Student Info =====");
       System.out.println(student1);
       SCD.graduateStudent(7777);
       System.out.println(" ===== Detailed Student Info 2 =====");
       System.out.println(SCD.getStudentInfo(7777));
       SCD.graduateStudent(5555);
       System.out.println(" ===== Detailed Course Info 6 =====");
       SCD.courseInfo(205);
       SCD.graduateStudent(5555);
       System.out.println(" ===== Good Job! Bye! =====");
   }
}


Sample Output:

===== Read Data 1 =====
Student Addition Failed - StudentId Exists

===== School Info 1 =====
School Name: SCD
Instructor Information
Y. Byun
S. Narayanan
M. Lara
S. Bude
Course Information
CST338 - Software Design
CST205 - Multimedia Design and Programming
CST306 - Game Engine Programming
Student Information
Alice Otter:CST338 - Software Design
Bob Otter:CST205 - Multimedia Design and Programming
===== Read Data 2 =====
Instructor Addition Failed - InstructorId Exists
Student Addition Failed - StudentId Exists
Student Addition Failed - StudentId Exists
Student Addition Failed - StudentId Exists

===== School Info 2 =====
School Name: SCD
Instructor Information
Y. Byun
S. Narayanan
M. Lara
S. Bude
G. Bruns
Course Information
CST338 - Software Design
CST205 - Multimedia Design and Programming
CST306 - Game Engine Programming
CST336 - Internet Programming
Student Information
Alice Otter:CST338 - Software Design
Bob Otter:CST205 - Multimedia Design and Programming
John Doe:CST338 - Software Design

===== Failed Course Addition =====
Course Addition Failed - CourseId Exists
Course Addition Failed - Non-exisiting Instructor

===== Detailed Course Info =====
Course Number: 306
Instructor: Y. Byun
Course Title: CST306 - Game Engine Programming
Room: BIT 104
Total Enrolled: 0

===== Detailed Course Info 2 =====
Course Number: 205
Instructor: S. Narayanan
Course Title: CST205 - Multimedia Design and Programming
Room: Library 104
Total Enrolled: 1
Course Avergae: 75

===== Detailed Course Info 3 =====
Number of Courses: 6
338: 2 enrolled
205: 1 enrolled
306: 0 enrolled
336: 0 enrolled
300: 0 enrolled
231: 0 enrolled
Course Deletion Successful
Course Deletion Successful
Course Deletion Failed - Enrolled student(s) in the class

===== Detailed Course Info 4 =====
Number of Courses: 4
338: 2 enrolled
205: 1 enrolled
306: 0 enrolled
300: 0 enrolled

===== Detailed Course Info 5 =====
Course Number: 205
Instructor: S. Narayanan
Course Title: CST205 - Multimedia Design and Programming
Room: Library 104
Total Enrolled: 2
Course Avergae: 80

===== Detailed Student Info =====
Student Number: 7777
Name: Alice Otter
Courses Enrolled:
338: 89.5(B)

===== Detailed Student Info 2 =====
Student Number: 7777
Name: Alice Otter
Courses Enrolled:
0: 89.5(B)

===== Detailed Course Info 6 =====
Course Number: 205
Instructor: S. Narayanan
Course Title: CST205 - Multimedia Design and Programming
Room: Library 104
Total Enrolled: 1
Course Avergae: 75

===== Good Job! Bye! =====

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