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

JAVA ECLIPSE PROGRAM First create the following five classes: 1. Person: first n

ID: 3719131 • Letter: J

Question

JAVA ECLIPSE PROGRAM


First create the following five classes:
1. Person: first name, last name, id, and phone number. It should be an abstract class.


2. Student: first name, last name, id, phone, gpa, major and a courseBag. The courseBag should contain courses taken, courses currently taking, and courses to be taken to graduate in a given major for each student. The information should be stored in one array or three arrays as String objects in the form of course numbers. Course grade should also be included for each course the student took. If you would like to use one array, you should also have a data field called courseType to indicate whether the students took, is taking or will need to take the said course for a given major.


3. Faculty: first name, last name, id, phone, title and salary Notice that the id numbers must be unique for the above three classes. They must be automatically generated sequentially starting from 1. They can NOT be changed or reused.


4. Textbook: book title, name of the author(s), publisher, book price, and the ISBN number (unique).


5. Course: course title, course number (unique), textbook assigned, and number of credits.


Note: each class should have some kind of custom exception handling capability to check data validity. They should be implemented in both constructors and setters. 
Also, make sure you use deep or shallow copy of objects appropriately.



Now create the following four bag classes:
1. PeopleBag: contains one array for both Student and Faculty objects.


2. TextBookBag: contains an array of the textbooks


3. MasterCourseBag: Contains a master list of all the courses offered in the college (but you just need to create at most twenty courses here).


4. CourseBag: As mentioned earlier, it should contain either one or three arrays. 

For each bag above, you need the following methods:


1. add() method to add objects into the bag.


2. display() method to display the whole content of the bag.


3. find() method to search the bag for individual object. For the PeopleBag, you search by id, for the TextbookBag, by ISBN number, and for the MasterCourseBag, by the course number


4. delete() method to delete a given object. For the PeopleBag, you delete by id, for the TextbookBag, by ISBN number, and for the MasterCourseBag,by the course number.


5. load() method to load data from a binary file previously saved for that bag to use.


6. save() method to save the bag / array(s) onto the hard drive as a binary file.


7. exportData() method to save the bag content into a text file.


8. importData() method to read data from a text file and then create objects using the data to put into the array. You may design your own data file.


Explanation / Answer

Hi Here is the file :
//Person.java

package Assignment2;

public abstract class Person

{

private String fName;

private String lName;

private Integer id;

private Integer phone;

public Person(String fName, String lName, Integer id, Integer phone)

{

this.fName = fName;

this.lName = lName;

this.id = id;

this.phone = phone;

}

public Person(String lName)

{

this.lName = lName;

}

// Getters

public String getfName()

{

return this.fName;

}

public String getlName()

{

return this.lName;

}

public Integer getID()

{

return this.id;

}

public Integer getPhone()

{

return this.phone;

}

// Setters

public void setFName(String name)

{

this.fName = name;

}

public void setLName(String name)

{

this.lName = name;

}

public void setID(Integer id)

{

this.id = id;

}

public void setPhone(Integer phone)

{

this.phone = phone;

}

@Override

public String toString()

{

return "Person [fName=" + fName + ", lName=" + lName + ", id=" + id

+ ", phone=" + phone + "]";

}

}


//Student.java

package Assignment2;

import java.io.Serializable;

import java.util.ArrayList;

import java.util.List;

public class Student extends Person implements Serializable

{

/**

*

*/

private static final long serialVersionUID = 1L;

// Data Field

private double gpa;

private String major;

private Integer credits;

List<Course> courses;

List<Course> inProgress;

List<Course> remaining;

public Student(String fName, String lName, Integer id, Integer phone)

{

super(fName, lName, id, phone);

courses = new ArrayList<>();

inProgress = new ArrayList<>();

remaining = new ArrayList<> ();

}

public double getGpa()

{

return gpa;

}

public void setGpa(double gpa)

{

this.gpa = gpa;

}

@Override

public String toString()

{

String temp = super.toString();

return "Student [" +temp.substring(8, temp.length()-1) +"," + " gpa=" + gpa + ", major=" + major + ", credits="

+ credits + ", courses=" + courses + ", inProgress="

+ inProgress + ", remaining=" + remaining + "]";

}

public String getMajor()

{

return major;

}

public void setMajor(String major)

{

this.major = major;

}

public Integer getCredits()

{

return credits;

}

public void setCredits(Integer credits)

{

this.credits = credits;

}

public List<Course> getCourses()

{

return courses;

}

public void setCourses(List<Course> courses)

{

this.courses = courses;

}

public List<Course> getInProgress()

{

return inProgress;

}

public void setInProgress(List<Course> inProgress)

{

this.inProgress = inProgress;

}

public List<Course> getRemaining()

{

return remaining;

}

public void setRemaining(List<Course> remaining)

{

this.remaining = remaining;

}

}


//Faculty.java

package Assignment2;

import java.io.Serializable;

public class Faculty extends Person implements Serializable

{

/**

*

*/

private static final long serialVersionUID = 1L;

// Data field

private String title;

private Integer payScale;

  

public Faculty(String fName, String lName, int id, int phone)

{

super(fName, lName, id, phone);

}

public Faculty(String lName)

{

super(lName);

}

  

// Getters and Setters

public String getTitle()

{

return title;

}

public void setTitle(String title)

{

this.title = title;

}

public int getPayScale()

{

return payScale;

}

public void setPayScale(Integer payScale)

{

this.payScale = payScale;

}

@Override

public String toString()

{

String temp = super.toString();

return "Faculty [" +temp.substring(8, temp.length()-1) + ", title=" + title + ", payScale=" + payScale + "]";

}

}


// TextBook.java

package Assignment2;

import java.io.Serializable;

public class TextBook implements Serializable

{

/**

*

*/

private static final long serialVersionUID = 1L;

private String title;

private String author;

private String publisher;

private Double price;

private Integer ISBN;

public TextBook(String title, String author, String publisher, Double price, Integer iSBN)

{

this.title = title;

this.author = author;

this.publisher = publisher;

this.price = price;

this.ISBN = iSBN;

}

public TextBook(String title)

{

this.title = title;

}

// Getters and setters

public String getTitle()

{

return title;

}

public void setTitle(String title)

{

this.title = title;

}

public String getAuthor()

{

return author;

}

public void setAuthor(String author)

{

this.author = author;

}

public String getPublisher()

{

return publisher;

}

public void setPublisher(String publisher)

{

this.publisher = publisher;

}

public Double getPrice()

{

return price;

}

public void setPrice(Double price)

{

this.price = price;

}

public Integer getISBN()

{

return ISBN;

}

public void setISBN(Integer iSBN)

{

this.ISBN = iSBN;

}

@Override

public String toString()

{

return "TextBook [title=" + title + ", author=" + author + ", publisher=" + publisher + ", price=" + price + ", ISBN=" + ISBN + "]";

}

}

//Course.java

package Assignment2;

import java.io.Serializable;

public class Course implements Serializable

{

/**

*

*/

private static final long serialVersionUID = 1L;

private String title;

private String number;

private Integer CRN;

private Integer credits;

private TextBook textBook;

public Course(String title, String number, Integer cRN, Integer credits, TextBook textBook)

{

this.title = title;

this.number = number;

this.CRN = cRN;

this.credits = credits;

this.textBook = textBook;

}

public Course(String title)

{

this.title = title;

}

public String getTitle()

{

return title;

}

public void setTitle(String title)

{

this.title = title;

}

public String getNumber()

{

return number;

}

public void setNumber(String number)

{

this.number = number;

}

public Integer getCRN()

{

return CRN;

}

public void setCRN(Integer cRN)

{

CRN = cRN;

}

public Integer getCredits()

{

return credits;

}

public void setCredits(Integer credits)

{

this.credits = credits;

}

public TextBook getTextBook()

{

return textBook;

}

public void setTextBook(TextBook textBook)

{

this.textBook = textBook;

}

@Override

public String toString()

{

return "Course [title=" + title + ", number=" + number + ", CRN=" + CRN + ", credits=" + credits + ", textBook=" + textBook + "]";

}

}

//PeopleBag.java

package Assignment2;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.ObjectInputStream;

import java.io.ObjectOutputStream;

import java.io.Serializable;

import java.util.ArrayList;

import java.util.List;

public class PeopleBag implements Serializable

{

/**

*

*/

private static final long serialVersionUID = 1L;

List<Student> studentList;

List<Faculty> facultyList;

private String result; // return value of Display

public PeopleBag()

{

studentList = new ArrayList<>();

facultyList = new ArrayList<>();

result = "";

}

public void add(Student student)

{

studentList.add(student);

}

public void add(Faculty faculty)

{

facultyList.add(faculty);

}

public String display()

{

// Students

result += " Student ";

for (Student s: studentList)

result += s.toString() + " ";

// Faculty

result += " Faculty ";

for (Faculty f: facultyList)

result += f.toString() + " ";

return result;

}

@SuppressWarnings("unchecked")

public <T> T find(Integer id)

{

for (Student s: studentList)

{

if (id.equals(s.getID()))

return (T)s;

}

for (Faculty f: facultyList)

{

if (id.equals(f.getID()))

return (T)f;

}

return null;

}

public boolean delete(Integer id)

{

for (Student s: studentList)

{

if (id.equals(s.getID()))

{

studentList.remove(s);

return true;

}

}

for (Faculty f: facultyList)

{

if (id.equals(f.getID()))

{

facultyList.remove(f);

return true;

}

}

return false;

}

public void save(String name) throws IOException

{

// write object to file

FileOutputStream fos = new FileOutputStream(name);

ObjectOutputStream oos = new ObjectOutputStream(fos);

oos.writeObject(this);

oos.close();

}

public void load(String name) throws IOException, ClassNotFoundException

{

// read object from file

FileInputStream fis = new FileInputStream(name);

ObjectInputStream ois = new ObjectInputStream(fis);

PeopleBag result = (PeopleBag) ois.readObject();

this.studentList = result.studentList;

this.facultyList = result.facultyList;

ois.close();

}

public void exportData(String name) throws IOException

{

// write object to file

FileOutputStream fos = new FileOutputStream(name);

ObjectOutputStream oos = new ObjectOutputStream(fos);

oos.writeObject(this);

oos.close();

}

public void importData(String name) throws IOException, ClassNotFoundException

{

// read object from file

FileInputStream fis = new FileInputStream(name);

ObjectInputStream ois = new ObjectInputStream(fis);

PeopleBag result = (PeopleBag) ois.readObject();

this.studentList = result.studentList;

this.facultyList = result.facultyList;

ois.close();

}

}


//TextBookBag.java

package Assignment2;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.ObjectInputStream;

import java.io.ObjectOutputStream;

import java.io.Serializable;

import java.util.ArrayList;

import java.util.List;

public class TextBookBag implements Serializable

{

/**

*

*/

private static final long serialVersionUID = 1L;

private List<TextBook> books;

private String result;

private int size;

public TextBookBag()

{

this.books = new ArrayList<>();

result = "";

size = 0;

}

public void add(TextBook book)

{

books.add(book);

size++;

}

public String display()

{

for (TextBook b: books)

result += b.toString() +" ";

return result;

}

public TextBook find(Integer ISBN)

{

for (TextBook b: books)

{

if (ISBN.equals(b.getISBN()))

return b;

}

return null;

}

public boolean delete(Integer ISBN)

{

for (TextBook b: books)

if (ISBN.equals(b.getISBN()))

{

books.remove(b);

size--;

return true;

}

return false;

}

public int size()

{

return size;

}

public void save(String name) throws IOException

{

// write object to file

FileOutputStream fos = new FileOutputStream(name);

ObjectOutputStream oos = new ObjectOutputStream(fos);

oos.writeObject(this);

oos.close();

}

public void load(String name) throws IOException, ClassNotFoundException

{

// read object from file

FileInputStream fis = new FileInputStream(name);

ObjectInputStream ois = new ObjectInputStream(fis);

TextBookBag result = (TextBookBag) ois.readObject();

this.books = result.books;

ois.close();

}

public void exportData(String name) throws IOException

{

// write object to file

FileOutputStream fos = new FileOutputStream(name);

ObjectOutputStream oos = new ObjectOutputStream(fos);

oos.writeObject(this);

oos.close();

}

public void importData(String name) throws IOException, ClassNotFoundException

{

// read object from file

FileInputStream fis = new FileInputStream(name);

ObjectInputStream ois = new ObjectInputStream(fis);

TextBookBag result = (TextBookBag) ois.readObject();

this.books = result.books;

ois.close();

}

}


//MasterCourseBag.java

package Assignment2;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.ObjectInputStream;

import java.io.ObjectOutputStream;

import java.io.Serializable;

import java.util.ArrayList;

import java.util.List;

public class MasterCourseBag implements Serializable

{

/**

*

*/

private static final long serialVersionUID = 1L;

List<Course> courses;

String result;

public MasterCourseBag()

{

courses = new ArrayList<>(20);

courses.add(new Course("Civil Engineering"));

courses.add(new Course("IT Engineering"));

courses.add(new Course("Electrical Engineering"));

courses.add(new Course("Bachelor of Science"));

courses.add(new Course("Bachelor of Arts"));

courses.add(new Course("Bachelor of Commerce"));

courses.add(new Course("Master of Science"));

courses.add(new Course("Master of Arts"));

courses.add(new Course("Master of Commerce"));

courses.add(new Course("M.Tech"));

courses.add(new Course("MS"));

courses.add(new Course("MBBS"));

courses.add(new Course("PHD"));

courses.add(new Course("BBA"));

courses.add(new Course("BCA"));

courses.add(new Course("CA"));

courses.add(new Course("CS"));

courses.add(new Course("Computer Science Engineering"));

courses.add(new Course("Mechanical Engineering"));

courses.add(new Course("Chemical Engineering"));

result = "";

}

public void add(Course course)

{

courses.add(course);

}

public String display()

{

for (Course c: courses)

result += c.toString() + " ";

return result;

}

public Course find(Integer CRN)

{

for (Course c: courses)

if (CRN.equals(c.getCRN()))

return c;

return null;

}

public boolean delete(Integer CRN)

{

for (Course c: courses)

if (CRN.equals(c.getCRN()))

{

courses.remove(c);

return true;

}

return false;

}

public void save(String name) throws IOException

{

// write object to file

FileOutputStream fos = new FileOutputStream(name);

ObjectOutputStream oos = new ObjectOutputStream(fos);

oos.writeObject(this);

oos.close();

}

public void load(String name) throws IOException, ClassNotFoundException

{

// read object from file

FileInputStream fis = new FileInputStream(name);

ObjectInputStream ois = new ObjectInputStream(fis);

CourseBag result = (CourseBag) ois.readObject();

this.courses = result.courses;

ois.close();

}

public void exportData(String name) throws IOException

{

// write object to file

FileOutputStream fos = new FileOutputStream(name);

ObjectOutputStream oos = new ObjectOutputStream(fos);

oos.writeObject(this);

oos.close();

}

public void importData(String name) throws IOException, ClassNotFoundException

{

// read object from file

FileInputStream fis = new FileInputStream(name);

ObjectInputStream ois = new ObjectInputStream(fis);

CourseBag result = (CourseBag) ois.readObject();

this.courses = result.courses;

ois.close();

}

}


//CourseBag.java

package Assignment2;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.ObjectInputStream;

import java.io.ObjectOutputStream;

import java.io.Serializable;

import java.util.ArrayList;

import java.util.List;

public class CourseBag implements Serializable

{

/**

*

*/

private static final long serialVersionUID = 1L;

List<Course> courses;

String result;

public CourseBag()

{

courses = new ArrayList<>();

result = "";

}

public void add(Course course)

{

courses.add(course);

}

public String display()

{

for (Course c: courses)

result += c.toString() + " ";

return result;

}

public Course find(Integer CRN)

{

for (Course c: courses)

if (CRN.equals(c.getCRN()))

return c;

return null;

}

public boolean delete(Integer CRN)

{

for (Course c: courses)

if (CRN.equals(c.getCRN()))

{

courses.remove(c);

return true;

}

return false;

}

public void save(String name) throws IOException

{

// write object to file

FileOutputStream fos = new FileOutputStream(name);

ObjectOutputStream oos = new ObjectOutputStream(fos);

oos.writeObject(this);

oos.close();

}

public void load(String name) throws IOException, ClassNotFoundException

{

// read object from file

FileInputStream fis = new FileInputStream(name);

ObjectInputStream ois = new ObjectInputStream(fis);

CourseBag result = (CourseBag) ois.readObject();

this.courses = result.courses;

ois.close();

}

public void exportData(String name) throws IOException

{

// write object to file

FileOutputStream fos = new FileOutputStream(name);

ObjectOutputStream oos = new ObjectOutputStream(fos);

oos.writeObject(this);

oos.close();

}

public void importData(String name) throws IOException, ClassNotFoundException

{

// read object from file

FileInputStream fis = new FileInputStream(name);

ObjectInputStream ois = new ObjectInputStream(fis);

CourseBag result = (CourseBag) ois.readObject();

this.courses = result.courses;

ois.close();

}

}