Question: I need help with my java homework. The code will be below. I am not sure which code needs to be edited so I will

I need help with my java homework. The code will be below. I am not sure which code needs to be edited so I will just post what I have.

Finish the class work. Complete the program regarding the Student and Course requests.

We enter from console the student code, and we get all the information about the student. We enter the code of the course and we get all the information about course. Write and read the information of the enrollments in file using serialized class Enrollment. Add a method in Controller that displays for each course the respective number of the students.

package com.example;

import java.io.Serializable; import java.util.ArrayList;

public class Course implements Serializable { private String code; private String description; private int credits; private ArrayList cEnrollments; public Course(String code, String description, int credits) { super(); this.code = code; this.description = description; this.credits = credits; cEnrollments=new ArrayList(); } public String getCode() { return code; } public void setCode(String code) { this.code = code; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public int getCredits() { return credits; } public void setCredits(int credits) { this.credits = credits; } public ArrayList getcEnrollments() { return cEnrollments; } public void setcEnrollments(Enrollment e) { cEnrollments.add(e); } public String toString() { String s="[course "+code+" "+description+" "+credits+"]"; for(Enrollment e:cEnrollments) { s+=" "+e.toString(); } return s; }

}

-----------------------------------------------------------------------

package com.example;

import java.io.Serializable; import java.util.Date;

public class Enrollment implements Serializable { private Student student; private Course course; private Date registration; public Enrollment(Student student, Course course, Date registration) { super(); this.student = student; this.course = course; this.registration = registration; } public Student getStudent() { return student; } public Course getCourse() { return course; } public Date getRegistration() { return registration; } public String toString() { return "[enrollment "+student.getCode()+" "+ course.getCode()+" "+registration+"]"; }

}

----------------------------------------------------------------------

package com.example;

import java.io.Serializable; import java.util.ArrayList;

public class Student implements Serializable { private String code; private String name; private int credits; private ArrayList sEnrollments; public Student(String code, String name, int credits) { this.code = code; this.name = name; this.credits = credits; sEnrollments=new ArrayList(); } public String getCode() { return code; } public void setCode(String code) { this.code = code; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getCredits() { return credits; } public void setCredits(int credits) { this.credits = credits; } public ArrayList getsEnrollments() { return sEnrollments; } public void setsEnrollments(Enrollment e) { sEnrollments.add(e); } public String toString() { String s="[student "+code+" "+name+" "+credits+"]"; for(Enrollment e:sEnrollments) { s+=" "+e.toString(); } return s; } }

------------------------------------------------------

package com.example;

import java.util.ArrayList; import java.util.Date;

public class Controller { private static final String[] studentCode= {"s100","s200","s300"}; private static final String[] studentName= {"student1","student2","student3"}; private static final int[] studentCredit= {20,25,15}; private static final String[] courseCode= {"cs1000","cs2000","cs3000"}; private static final String[] courseName= {"Java","C++","Android"}; private static final int[] courseCredit= {4,4,3}; private static final String[] regStudentCode= {"s100","s100","s200","s200","s300","s300"}; private static final String[] regCourseCode= {"cs1000","cs2000","cs1000","cs2000","cs2000","cs3000"}; private static final String[] regDate= {"2019/1/09","2019/1/10","2019/1/15","2019/1/09","2019/1/10","2019/1/15"}; private ArrayList courses; private ArrayList students; private ArrayList enrollments; public Controller() { courses=new ArrayList(); students=new ArrayList(); enrollments=new ArrayList(); fillLists(); } private void fillLists() { for(int i=0;i Student s=new Student(studentCode[i],studentName[i], studentCredit[i]); students.add(s); } for(int i=0;i Course c=new Course(courseCode[i],courseName[i], courseCredit[i]); courses.add(c); } for(int i=0;i Student sObj=null; Course cObj=null; for(Student s: students) { if(s.getCode().equals(regStudentCode[i])) sObj=s; } for(Course c: courses) { if(c.getCode().equals(regCourseCode[i])) cObj=c; } if(sObj!=null&&cObj!=null) { Enrollment e=new Enrollment(sObj,cObj,new Date(regDate[i])); enrollments.add(e); } } } private void filStudentEnroll() { for(Student s: students) { for (Enrollment e: enrollments) { if(s.getCode().equals(e.getStudent().getCode())) s.setsEnrollments(e); } } } }

---------------------------------------------------------------------------------

package com.example;

public class Main {

public static void main(String[] args) { Controller controller= new Controller(); //controller.displayInfo(); controller.writeReadSerializable();

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!