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

Listed below are 3 things: my code, the instructions, and the example from the t

ID: 3678902 • Letter: L

Question

Listed below are 3 things: my code, the instructions, and the example from the textbook.

Fix the code to make sure it matches in the instructions. The textbook example should help if something seems to be missing.

My code:

public class Person {

     

      // Instance variables

      private String name;

     

      // Constructor

      public Person(String name) {

            this.name = name;

      }

     

      // Getters

      public String getName() {

            return name;

      }

     

      // Setters

      public void setName(String name) {

            this.name = name;

      }

      // toString method of this class

      @Override

      public String toString() {

            return "Person [name=" + name + "]";

      }

     

      // Write output method that outputs all the values of instance variables

      public String writeOutput() {

            // We just need to call toString() in this method

            return toString();

      }

}

public class Employee extends Person {

      // Instance variables

      private int employeeID;

      private String dept;

     

      // Constructor

      public Employee(String name, int employeeID, String dept) {

            super(name);

            this.employeeID = employeeID;

            this.dept = dept;

      }

      // Getters

      public int getEmployeeID() {

            return employeeID;

      }

      public String getDept() {

            return dept;

      }

      // Setters

      public void setEmployeeID(int employeeID) {

            this.employeeID = employeeID;

      }

      public void setDept(String dept) {

            this.dept = dept;

      }

     

      // toString method of this class

      @Override

      public String toString() {

            return "Employee [employeeID=" + employeeID + ", dept=" + dept + "]";

      }

     

      // Write output method that outputs all the values of instance variables

      public String writeOutput() {

            // We just need to call toString() in this method

            return toString();

      }

}

public class Faculty extends Person {

     

      // Instance variables

      private String title;

      // Constructor

      public Faculty(String name, String title) {

            super(name);

            this.title = title;

      }

      // Getters

      public String getTitle() {

            return title;

      }

      // Setters

      public void setTitle(String title) {

            this.title = title;

      }

      // toString method of this class

      @Override

      public String toString() {

            return "Faculty [title=" + title + "]";

      }

     

      // Write output method that outputs all the values of instance variables

      public String writeOutput() {

            // We just need to call toString() in this method

            return toString();

      }

}

public class Staff extends Person{

     

      // Instance variables

      private int payGrade;

      // Constructor

      public Staff(String name, int payGrade) {

            super(name);

            this.payGrade = payGrade;

      }

     

      // Getters

      public int getPayGrade() {

            return payGrade;

      }

      // Setters

      public void setPayGrade(int payGrade) {

            this.payGrade = payGrade;

      }

      // toString method of this class

      @Override

      public String toString() {

            return "Staff [payGrade=" + payGrade + "]";

      }

     

      // Write output method that outputs all the values of instance variables

      public String writeOutput() {

            // We just need to call toString() in this method

            return toString();

      }

}

Instruction

Don't hard code it.

Use the scanner readfile to process the code.

This HW is loosely based on the description of Programming Projects 6 and 7 (pages 664 & 665) in Chapter 8 of your text. Follow the class discussions and specifications below to receive credits.

Program 6

For this Programming Project, start with implementations of the Person, Student, and Undergraduate classes as depicted in Figure 8.4 and the polymorphism demo in listing 8.6. Define the Employee, Faculty, and Staff.

Use (Student.class) classes as depicted in Figure 8.2. the Employee class should have instance variables to store the employee ID as an int and the employee’s department as a String. The Faculty class should have an instance variable to store the faculty member’s title (e.g., “Professor of Computer Science”) as a String. The Staff class should have an instance variable to store the staff member’s pay grade (a number from 1 to 20) as an int.

Every class should have appropriate constructors, accessors, and mutators, along with a writeOutput method that outputs all of the instance variable values.

     5.     Modify the program in listing 8.6 to include at least one Faculty object and at least one Staff object in addition to the Undergraduate and Student objects. Without modification to the for loop, the report should output the name, employee ID, department, and title for the Faculty objects, and the name, employee ID, department, and pay grade for the Staff

objects.

Program 7

modify the Student class in     listing 8.2 so that it implements the Comparable interface. Define the compareTo method to order Student objects based on the value in studentNumber. In a main method create an array of at least five Student objects, sort them using Arrays.sort, and output the students. They should be listed by ascending student number. next, modify the compareTo method so it orders Student objects based on the lexicographic ordering of the name variable. Without modification to the main method, the program should now output the students ordered by name.

Read a file, polymorph.txt, to instantiate three groups of people -- student, staff, and faculty. The file has the format below.

student stu26974 78203        // object type, name, ID

undergraduate stu36271 07493 History 3       // object type, name, ID, major, year

graduate stu84710 72068 Computer_Science, 1, Math      //object type, name, ID, grad major, year, undergraduate major

staff sta32 4328 Student_Service_Specialist 15        // object type, name, ID, title, pay grade

faculty fac498 872 Computer_Science Professor      // object type, name, ID, department, title

8. I will test your code with at least 20 entities per the specs above.

9. You must use the concepts - inheritance, polymorphism, and interfaces - that we discussed in class to complete this assignment.

10. You must implement the toString() method for each type of object.

11. Follow the output session below to receive credits:

The following objects are instantiated from the polymorph.txt file.

... // show all the details of each object; use the same format as Listing 8.6

... // make sure that you use the toString() method

... // sort by name, then ID

12. The following students are sorted based on Student_ID, Student_Name, and Year, in that sequence:

... // sort by ID first, then name, then year; use the toString() method

The following staff are sorted based on Staff_Name, and ID, in that sequence:

... // sort by name first, then staff ID; use the toString() method

The following faculty are sorted based on department:

... // use the toString() method

Examples from the textbook:

Example #1:

public class Person

{

    private String name;

   

    public Person( )

    {

        name = "No name yet";

    }

   

    public Person(String initialName)

    {

        name = initialName;

    }

   

    public void setName(String newName)

    {

        name = newName;

    }

   

    public String getName( )

    {

        return name;

    }

   

    public void writeOutput( )

    {

        System.out.println("Name: " + name);

    }

  

    public boolean hasSameName(Person otherPerson)

    {

        return this.name.equalsIgnoreCase(otherPerson.name);

    }

}

Example #2

public class Student extends Person

{

    private int studentNumber;

    public Student( )

    {

        super( );

        studentNumber = 0;//Indicating no number yet

    }

    public Student(String initialName, int initialStudentNumber)

    {

        super(initialName);

        studentNumber = initialStudentNumber;

    }

    public void reset(String newName, int newStudentNumber)

    {

        setName(newName);

        studentNumber = newStudentNumber;

    }

    public int getStudentNumber( )

    {

        return studentNumber;

    }

    public void setStudentNumber(int newStudentNumber)

    {

        studentNumber = newStudentNumber;

    }

Example #3

public class PolymorphismDemo

{

                public static void main(String[] args)

                {

                                Person[] people = new Person[4];

                                people[0] = new Undergraduate("Cotty, Manny", 4910, 1);

                                people[1] = new Undergraduate("Kick, Anita", 9931, 2);

                                people[2] = new Student("DeBanque, Robin", 8812);

                                people[3] = new Undergraduate("Bugg, June", 9901, 4);

                                for (Person p : people)

                                {

                                                p.writeOutput();

                                                System.out.println();

                                }

                }

}

Example #4:

public class Undergraduate extends Student

{

    private int level; //1 for freshman, 2 for sophomore,

                       //3 for junior, or 4 for senior.

    public Undergraduate( )

    {

        super( );

        level = 1;

    }

   

    public Undergraduate(String initialName, int initialStudentNumber,

                         int initialLevel)

    {

        super(initialName, initialStudentNumber);

        setLevel(initialLevel); //Checks 1 <= initialLevel <= 4

    }

   

    public void reset(String newName, int newStudentNumber,

                                  int newLevel)

    {

        reset(newName, newStudentNumber); //StudentÕs reset

        setLevel(newLevel); //Checks 1 <= newLevel <= 4

    }

   

    public int getLevel( )

    {

        return level;

    }

   

    public void setLevel(int newLevel)

    {

        if ((1 <= newLevel) && (newLevel <= 4))

            level = newLevel;

        else

        {

            System.out.println("Illegal level!");

            System.exit(0);

        }

    }

   

    public void writeOutput( )

    {

        super.writeOutput( );

       System.out.println("Student Level: " + level);

    }

    public boolean equals(Undergraduate otherUndergraduate)

    {

        return equals((Student)otherUndergraduate) &&

               (this.level == otherUndergraduate.level);

    }

/* // Alternate version

    public boolean equals(Undergraduate otherUndergraduate)

    {

        return super.equals(otherUndergraduate) &&

               (this.level == otherUndergraduate.level);

    }

*/          

}

Example #5:

public class UndergraduateDemo

{

    public static void main(String[] args)

    {

        Undergraduate ug1 = new Undergraduate("James Bond", 007, 1);

        ug1.writeOutput();

        ug1.reset("Sam Spade", 1940, 2);

        System.out.println("ug1 is:");

        ug1.writeOutput();

        Undergraduate ug2 = new Undergraduate("James Bond", 007, 1);

        System.out.println(" ug2 is:");

        ug2.writeOutput();

        if (ug1.equals(ug2))

            System.out.println("Same students.");

        else

            System.out.println("Not the same students.");

       //hasSameName inherited from Student, which inherited it from Person.

        if (ug1.hasSameName(ug2))

            System.out.println("Same names.");

        else

            System.out.println("Not the same names.");

        Undergraduate ug3 = new Undergraduate("James Bond", 007, 1);

        System.out.println(" ug3 is:");

        ug3.writeOutput();

        if (ug3.equals(ug2))

            System.out.println("Same students.");

        else

            System.out.println("Not the same students.");

    }

}

Example #6:

public class Fruit implements Comparable

{

                private String fruitName;

                public Fruit()

                {

                                fruitName = "";

                }

                public Fruit(String name)

                {

                                fruitName = name;

                }

                public void setName(String name)

                {

                                fruitName = name;

                }

                public String getName()

                {

                                return fruitName;

                }

                public int compareTo(Object o)

                {

                                if ((o != null) &&

                                    (o instanceof Fruit))

                                {

                                                Fruit otherFruit = (Fruit) o;

                                                return (fruitName.compareTo(otherFruit.fruitName));

/*** Alternate definition of comparison using fruit length ***/

/*

                                                if (fruitName.length() > otherFruit.fruitName.length())

                                                                return 1;

                                                else if (fruitName.length() < otherFruit.fruitName.length())

                                                                return -1;

                                                else

                                                                return 0;

*/

                                }

                                return -1;                             // Default if other object is not a Fruit

                }

}

Example #7:

import java.util.Arrays;

public class FruitDemo

{

                public static void main(String[] args)

                {

                                Fruit[] fruits = new Fruit[4];

                                fruits[0] = new Fruit("Orange");

                                fruits[1] = new Fruit("Apple");

                                fruits[2] = new Fruit("Kiwi");

                                fruits[3] = new Fruit("Durian");

                                Arrays.sort(fruits);

                                // Output the sorted array of fruits

                                for (Fruit f : fruits)

                                {

                                                System.out.println(f.getName());

                                }

                }

}

Explanation / Answer

Hey I have checked your code for more than 7-8 times I dont think theres anything wrong in your code. Implement undergraduate class and other classes too. If you have given me whole code with main class then I could have compiled it and fixed it.

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