Question

PLEASE DO IN JAVA 1) Create interface named “Person” which exposes getter/setter methods for the person’s...

PLEASE DO IN JAVA

1) Create interface named “Person” which exposes getter/setter methods for the person’s name and college ID: 1. getName 2. setName 3. getID 4. setID. The college ID is represented as “int”. Define two classes, Student and Faculty, which implement Person. Add field GPA to Student and department to faculty. Make them private and create corresponding getters (getGPA, getDepartment) and setters (setGPA, setDepartment). Use appropriate types.

2) Write a class College, which contains the name of the college and a single private array that can store up to 100 students and faculties. Write the following methods: 1. addPerson: takes a student or a faculty as parameter and adds it to the college 2. setName: and getName: get and set the name of the college

3) Add the following method to College: 1. sort(): moves all students to the first positions of the array, and all faculties after that. As an example, let fn indicate faculty n and sn indicate student n. If the array contains s1|f1|f2|s2|s3|f3|s4, after invoking sort the array will contain s1|s2|s3|s4|f1|f2|f3 (this does not have to be done “in place”). Students and faculty are sorted by last name. You can use any number of auxiliary (private) methods, if needed.

4) Add a method storeCollege(String filename) to College. This method saves all the college information in a file (name specified in variable filename). Use ObjectOutputStream and write one single object. Add method loadStoreCollege(String filename) which loads the information written by storeCollege.

5) Add the program’s main method to College. The main method instantiates a new College, adds some faculty and students in random order (populated with their name and ID), sorts them using the code in Part 3, and stores them into a file. It then instantiates a new college that loads the data previously written to file, and verifies that the first and second college contain identical data. The main method does not ask for any input from the terminal.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

thanks for the question, please post only 1 question at a time. As per Chegg policy, we are limited to answering only the first question. I have solved Question 1 and Question 2.

Please post question 3,4 and 5 as a separate post and I will solve the rest. Sorry for the inconvenience caused here.

Here are the 4 files you will be needing as part of Question 1 and 2

==============================================================================

// Part 1

public interface Person {
   
    public void setName(String name);
    public String getName();

    public void setID(String id);
    public String getID();
}

public class Student implements Person {



    private String name;

    private String studentID;

    private double GPA;



    public Student() {

        name = "";

        studentID = "";

        GPA = 0;

    }



    public Student(String name, String studentID) {

        this.name = name;

        this.studentID = studentID;

    }



    public Student(String name, String studentID, double GPA) {

        this.name = name;

        this.studentID = studentID;

        this.GPA = GPA;

    }



    public double getGPA() {

        return GPA;

    }



    public void setGPA(double GPA) {

        this.GPA = GPA;

    }



    @Override

    public void setName(String name) {

        this.name = name;

    }



    @Override

    public String getName() {

        return name;

    }



    @Override

    public void setID(String id) {

        this.studentID = id;

    }



    @Override

    public String getID() {

        return studentID;

    }

}
public class Faculty implements Person {



    private String name;

    private String facultyID;

    private String  department;



    public Faculty() {

        name = "";

        facultyID = "";

        department = "";

    }



    public Faculty(String name, String studentID) {

        this.name = name;

        this.facultyID = studentID;

    }



    public Faculty(String name, String studentID, String department) {

        this.name = name;

        this.facultyID = studentID;

        this.department = department;

    }



    public String getDepartment() {

        return department;

    }



    public void setDepartment(String department) {

        this.department = department;

    }



    @Override

    public void setName(String name) {

        this.name = name;

    }



    @Override

    public String getName() {

        return name;

    }



    @Override

    public void setID(String id) {

        this.facultyID = id;

    }



    @Override

    public String getID() {

        return facultyID;

    }

}

// Part 2

public class College {



    private String collegeName;

    private Person persons[];

    private int count;



    public College(String collegeName) {

        this.collegeName = collegeName;

        persons = new Person[100];

        count = 0;

    }



    public void addPerson(Person aPerson) {

        if (count < persons.length) {

            persons[count++] = aPerson;

        }

    }



    public String getName() {

        return collegeName;

    }



    public void setName(String collegeName) {

        this.collegeName = collegeName;

    }

}

==================================================================

Add a comment
Know the answer?
Add Answer to:
PLEASE DO IN JAVA 1) Create interface named “Person” which exposes getter/setter methods for the person’s...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PLEASE DO IN JAVA 3) Add the following method to College: 1. sort(): moves all students...

    PLEASE DO IN JAVA 3) Add the following method to College: 1. sort(): moves all students to the first positions of the array, and all faculties after that. As an example, let fn indicate faculty n and sn indicate student n. If the array contains s1|f1|f2|s2|s3|f3|s4, after invoking sort the array will contain s1|s2|s3|s4|f1|f2|f3 (this does not have to be done “in place”). Students and faculty are sorted by last name. You can use any number of auxiliary (private) methods, if needed....

  • Modify the objectstudent JAVA program to add a private variable zipcode, you must also add setters...

    Modify the objectstudent JAVA program to add a private variable zipcode, you must also add setters and getter methods for the new variable and modify the toString method. The objectstudent program is in this weeks module, you can give it a default value of 19090. class Student { private int id; private String name; public Student() { id = 8; name = "John"; } public int getid() { return id; } public String getname() { return name; } public void...

  • I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student...

    I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student {    private String name;    private double gpa;    private int idNumber;    public Student() {        this.name = "";        this.gpa = 0;        this.idNumber = 0;    }    public Student(String name, double gpa, int idNumber) {        this.name = name;        this.gpa = gpa;        this.idNumber = idNumber;    }    public Student(Student s)...

  • Set-Up · Create a new project in your Eclipse workspace named: Lab13 · In the src...

    Set-Up · Create a new project in your Eclipse workspace named: Lab13 · In the src folder, create a package named: edu.ilstu · Import the following files from T:\it168\Labs\lab13. Note that the .txt file must be in the top level of your project, not inside your src folder. o Student.java o StudentList.java o students.txt Carefully examine the Student.java and StudentList.java files. You are going to complete the StudentList class (updating all necessary Javadoc comments), following the instruction in the code....

  • Last name is Vhora 3. Write a java class named FinalyourLastName, which contains three methods: main,...

    Last name is Vhora 3. Write a java class named FinalyourLastName, which contains three methods: main, arrayMystery, and countTotalOdd. You need to create main method. Inside the main method...you need to create an integer array named myld that consists of each of the digits in your student ID, call arrayMystery method and print out myld, then call count TotaOdd method and print out the total number of odd digits in your ID. (8 points) The arrayMystery method is given as...

  • Hi, I am writing Java code and I am having a trouble working it out. The...

    Hi, I am writing Java code and I am having a trouble working it out. The instructions can be found below, and the code. Thanks. Instructions Here are the methods needed for CIS425_Student: Constructor: public CIS425_Student( String id, String name, int num_exams ) Create an int array exams[num_exams] which will hold all exam grades for a student Save num_exams for later error checking public boolean addGrade( int exam, int grade ) Save a grade in the exams[ ] array at...

  • Please help me do the java project For this project you will be reading in a...

    Please help me do the java project For this project you will be reading in a text file and evaluating it in order to create a new file that represents the Class that will represent the properties of the text file. For example, consider the following text file: students.txt ID              Name                              Age                    IsMale           GPA 1                Tom Ryan                       22                       True              3.1 2                Jack Peterson                31                       True              2.7 3                Cindy LuWho                12                       False             3.9 When you read in the header line, you...

  • please help asap in c++, you dont have to do everything but at least give me...

    please help asap in c++, you dont have to do everything but at least give me a starting idea of how this should look like Write a class Assignment that has private attributes for Name, Possible Points and Earned Points Write a class Student that has private attributes for name and a vector of assignments. The constructor method should require a name. Add a method for get total score that returns the total number of points earned divided by the...

  • Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   and please put comment with code! Problem:2 1. Class Student Create...

    Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   and please put comment with code! Problem:2 1. Class Student Create a "Hello C++! I love CS52" Program 10 points Create a program that simply outputs the text Hello C++!I love CS52" when you run it. This can be done by using cout object in the main function. 2. Create a Class and an Object In the same file as...

  • java This lab is intended to give you practice creating a class with a constructor method,...

    java This lab is intended to give you practice creating a class with a constructor method, accessor methods, mutator methods, equals method , toString method and a equals method. In this lab you need to create two separate classes, one Student class and other Lab10 class. You need to define your instance variables, accessor methods, mutator methods, constructor, toString method and equals method in Student class. You need to create objects in Lab10 class which will have your main method...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT