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

need Java Help Develop a registration system for students. Each student has name

ID: 3697461 • Letter: N

Question

need Java Help

Develop a registration system for students. Each student has name, id, major, and a list of registered courses. Each course has code, name, credit hours and letter grade. Your program should read the data once from the file "student.txt" then display a menu with the following options: Display registered courses for a student and his SPA Display students in a course Add a course to a student Drop a course from a student Save data to the file Quit All modifications should be done on the array not to the file. Notes: Teams of two students will be formed. Demo will be done on Wednesday May 4, 2016 Submit the project (java files + report) on blackboard only. The report is a document that has the description of your program and how you implemented it. After that, the report should have snapshots of your program while running. Late work is not accepted. Copying will result in a grade of F in the course.

Explanation / Answer

Student.java

package student.course;

import java.io.Serializable;
import java.util.List;

public class Student implements Serializable{
   private String name;
   private int id;
   private String major;
   private List<Course> registeredCourses;
   private double gpa;
   public String getName() {
       return name;
   }
   public void setName(String name) {
       this.name = name;
   }
   public int getId() {
       return id;
   }
   public void setId(int id) {
       this.id = id;
   }
   public String getMajor() {
       return major;
   }
   public void setMajor(String major) {
       this.major = major;
   }
   public List<Course> getRegisteredCourses() {
       return registeredCourses;
   }
   public void setRegisteredCourses(List<Course> registeredCourses) {
       this.registeredCourses = registeredCourses;
   }
   public double getGpa() {
       return gpa;
   }
   public void setGpa(double gpa) {
       this.gpa = gpa;
   }
   public Student(String name, int id, String major, List<Course> registeredCourses, double gpa) {
       super();
       this.name = name;
       this.id = id;
       this.major = major;
       this.registeredCourses = registeredCourses;
       this.gpa = gpa;
   }
  
   public Student(int id) {
       super();
       this.id = id;
   }
   @Override
   public String toString() {
       return "Student [name=" + name + ", id=" + id + ", major=" + major + ", registeredCourses=" + registeredCourses
               + ", gpa=" + gpa + "]";
   }
   @Override
   public int hashCode() {
       final int prime = 31;
       int result = 1;
       result = prime * result + id;
       return result;
   }
   @Override
   public boolean equals(Object obj) {
       if (this == obj)
           return true;
       if (obj == null)
           return false;
       if (getClass() != obj.getClass())
           return false;
       Student other = (Student) obj;
       if (id != other.id)
           return false;
       return true;
   }
  
  
  
  
}

Course.java

package student.course;

public class Course {
   private int code;
   private String name;
   private int creditHours;
   @Override
   public int hashCode() {
       final int prime = 31;
       int result = 1;
       result = prime * result + code;
       return result;
   }
   @Override
   public boolean equals(Object obj) {
       if (this == obj)
           return true;
       if (obj == null)
           return false;
       if (getClass() != obj.getClass())
           return false;
       Course other = (Course) obj;
       if (code != other.code)
           return false;
       return true;
   }
   public Course(int code) {
       super();
       this.code = code;
   }
  
  
}

Registraition.java

package student.course;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.List;
import java.util.Scanner;

public class Registration {
   public static void main(String[] args) {
       Scanner scanner = new Scanner(System.in);
       int response = 0;
       int studentId, courseCode;
       List<Student> students = readStudents();
       do {
           System.out.println("1 - Display registered courses for a student and his GPA");
           System.out.println("2 - Display students in a course");
           System.out.println("3 - Add a course to a student");
           System.out.println("4 - Drop a course from a student");
           System.out.println("5 - Save data to the file");
           System.out.println("6 - Quit");
           response = scanner.nextInt();
          
           switch(response) {
           case 1:
               System.out.println("Enter student id");
               studentId = scanner.nextInt();
               Student student = new Student(studentId);
               for (Student currentStudent: students) {
                   if (student == currentStudent) {
                       System.out.println(currentStudent.getRegisteredCourses());
                       System.out.println(currentStudent.getGpa());
                   }
               }
               break;
              
           case 2:
               System.out.println("Enter course code");
               courseCode = scanner.nextInt();
               Course course = new Course(courseCode);
               for (Student currentStudent: students) {
                   if (currentStudent.getRegisteredCourses().contains(course))
                       System.out.println(currentStudent.getName());
               }
               break;
              
           case 3:
               System.out.println("Enter student id");
               studentId = scanner.nextInt();
               System.out.println("Enter course code");
               courseCode = scanner.nextInt();
               student = new Student(studentId);
               course = new Course(courseCode);
               for (Student currentStudent: students) {
                   if (student == currentStudent) {
                       currentStudent.getRegisteredCourses().add(course);
                   }
               }
               break;
              
           case 4:
               System.out.println("Enter student id");
               studentId = scanner.nextInt();
               System.out.println("Enter course code");
               courseCode = scanner.nextInt();
               student = new Student(studentId);
               course = new Course(courseCode);
               for (Student currentStudent: students) {
                   if (student == currentStudent) {
                       currentStudent.getRegisteredCourses().remove(course);
                   }
               }
               break;
              
           case 5:
               try{
                   FileOutputStream fout = new FileOutputStream("student.txt");
                   ObjectOutputStream oos = new ObjectOutputStream(fout);   
                   oos.writeObject(students);
                   oos.close();
                   System.out.println("Done");
                     
               }catch(Exception ex){
                   ex.printStackTrace();
               }
               break;
           }
       } while (response != 6);
      
   }
  
   private static List<Student> readStudents() {
       try{
           FileInputStream fin = new FileInputStream("student.txt");
           ObjectInputStream ois = new ObjectInputStream(fin);
           List<Student> students = (List<Student>) ois.readObject();
           ois.close();
          
           return students;
             
       }catch(Exception ex){
           ex.printStackTrace();
           return null;
       }
   }
}