Question

In: Computer Science

Java Question Design a class named Person and its two subclasses named Student and Employee. Make...

Java Question

Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name, address, phone number, and email address. A student has a class status (freshman, sophomore, junior, or senior). Define the status as a constant. An employee has an office, salary, and date hired. Use the Date class to create an object for date hired. A faculty member has office hours and a rank. A staff member has a title. Override the toString method in each class to display the class name and the person’s name. Write a test class that creates a Person, Student, Employee, Faculty, and Staff, and invokes their toString() methods.

Solutions

Expert Solution

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
=================================

// Person.java

public class Person {

// Declaring variables

private String name, address;

private String phoneNo;

private String email;

// Zero Argument Constructor

public Person() {

super();

}

public Person(String name, String address,String phoneNo,String email) {

super();

this.name = name;

this.address = address;

this.phoneNo=phoneNo;

this.email=email;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getAddress() {

return address;

}

public void setAddress(String address) {

this.address = address;

}

public String getPhoneNo() {

return phoneNo;

}

public void setPhoneNo(String phoneNo) {

this.phoneNo = phoneNo;

}

public String getEmail() {

return email;

}

public void setEmail(String email) {

this.email = email;

}

@Override

public String toString() {

return "Name=" + name + ", Address=" + address + ", Phone No="

+ phoneNo + ", email=" + email;

}

}

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

// Student.java

public class Student extends Person {
private final String classStatus;
public Student(String classStatus) {
this.classStatus = classStatus;
}
public Student(String name, String address,String phoneNo,String email, String classStatus) {
super(name, address,phoneNo,email);
this.classStatus = classStatus;
}
public String toString() {
return super.toString() + " Satus= " + this.classStatus;
}
}

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

// MyDate.java

public class MyDate {

private int year;

private int month;

private int day;

public MyDate(int year, int month, int day) {

super();

this.year = year;

this.month = month;

this.day = day;

}

public int getYear() {

return year;

}

public void setYear(int year) {

this.year = year;

}

public int getMonth() {

return month;

}

public void setMonth(int month) {

this.month = month;

}

public int getDay() {

return day;

}

public void setDay(int day) {

this.day = day;

}

@Override

public String toString() {

return month+"/"+day+"/"+year;

}

}

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

// Employee.java

public class Employee extends Person {
// Declaring variables
private String office;
private double salary;
private MyDate dateHired;
// Zero Argument Constructor
public Employee() {
super();
}
// Parameterized constructor.
public Employee(String name, String address, String phoneNo,String email, String office, double salary,MyDate datehired) {
super(name, address, phoneNo, email);
this.office = office;
this.salary = salary;
this.dateHired=datehired;
}
// Setters and getters
public String getOffice() {
return office;
}
public void setOffice(String office) {
this.office = office;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
// toString() method displays the contents of the object.
@Override
public String toString() {
return super.toString() + " office=" + office + ", salary=" + salary;
}
}

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

// Faculty.java

public class Faculty extends Employee {

   // Declaring variables

   private int office_hours;
private int rank;
   // Zero Argument Constructor

   public Faculty() {

       super();

   }

   // Parameterized constructor.

   public Faculty(String name, String address, String phoneNo, String email,
           String office, double salary, MyDate datehired,

           int office_hours,int rank) {

       super(name, address, phoneNo, email, office, salary, datehired);

       this.office_hours = office_hours;
       this.rank=rank;

   }

   // Setters and getters
  

   public int getOffice_hours() {

       return office_hours;

   }

   /**
   * @return the rank
   */
   public int getRank() {
       return rank;
   }

   /**
   * @param rank the rank to set
   */
   public void setRank(int rank) {
       this.rank = rank;
   }

   public void setOffice_hours(int office_hours) {

       this.office_hours = office_hours;

   }

   // toString() method displays the contents of the object.

   @Override
   public String toString() {

       return super.toString() + " office_hours=" + office_hours+", Rank="+rank;

   }

}

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

// Staff.java

public class Staff extends Employee {

// Declaring variables

private String title;

// Zero Argument Constructor

public Staff() {

super();

}

// Parameterized constructor.

public Staff(String name, String address,String phoneNo,String email, String office, double salary,MyDate datehired,

String title) {

super(name, address,phoneNo,email, office, salary,datehired);

this.title = title;

}

// Setters and getters

public String getTitle() {

return title;

}

public void setTitle(String title) {

this.title = title;

}

// toString() method displays the contents of the object.

@Override

public String toString() {

return super.toString() + " Title=" + title;

}

}

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

// Test.java

import java.util.ArrayList;

public class Test {

   public static void main(String[] args) {

       ArrayList<Person> al = new ArrayList<Person>();

       al.add(new Student("James", "101 Church Street", "9848425879",
               "[email protected]", "Sophomore"));

       al.add(new Employee("Pattinson", "44 That Street", "9848424345",
               "[email protected]", "Accenture", 45000, new MyDate(2014,
                       04, 23)));

       al.add(new Faculty("Williams", "500 Over There Street", "9843567845",
               "[email protected]", "Accenture", 50000, new MyDate(2012, 4,
                       12), 8,3));

       al.add(new Staff("James", "867 Hay Street", "9845677667",
               "[email protected]", "Microsoft", 80000, new MyDate(2014, 05,
                       21), "Janitor"));

       for (int i = 0; i < al.size(); i++)

       {

           if (al.get(i) instanceof Faculty)

               System.out.println("Faculty " + al.get(i).toString());

           else if (al.get(i) instanceof Staff)

               System.out.println("Staff " + al.get(i).toString());

           else if (al.get(i) instanceof Student)

               System.out.println("Student " + al.get(i).toString());

           else if (al.get(i) instanceof Employee)

               System.out.println("Employee " + al.get(i).toString());

       }

   }

}

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

Output:

Student Name=James, Address=101 Church Street, Phone No=9848425879, [email protected] Satus= Sophomore
Employee Name=Pattinson, Address=44 That Street, Phone No=9848424345, [email protected] office=Accenture, salary=45000.0
Faculty Name=Williams, Address=500 Over There Street, Phone No=9843567845, [email protected] office=Accenture, salary=50000.0 office_hours=8, Rank=3
Staff Name=James, Address=867 Hay Street, Phone No=9845677667, [email protected] office=Microsoft, salary=80000.0 Title=Janitor

=====================Could you plz rate me well.Thank You


Related Solutions

This assignment will use the Employee class that you developed for assignment 6. Design two subclasses...
This assignment will use the Employee class that you developed for assignment 6. Design two subclasses of Employee…SalariedEmployee and HourlyEmployee. A salaried employee has an annual salary attribute. An hourly employee has an hourly pay rate attribute, an hours worked attribute, and an earnings attribute. An hourly employee that works more than 40 hours gets paid at 1.5 times their hourly pay rate. You will decide how to implement constructors, getters, setters, and any other methods that might be necessary....
This is 1 java question with its parts. Thanks so much! Create a class named Student...
This is 1 java question with its parts. Thanks so much! Create a class named Student that has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. A Student also has a field for grade point average....
(Java) Design a class named Person with fields for holding a person’s name, address, and telephone...
(Java) Design a class named Person with fields for holding a person’s name, address, and telephone number. Write one or more constructors and the appropriate mutator and accessor methods for the class’s fields. Next, design a class named Customer, which extends the Person class. The Customer class should have a field for a customer number and a boolean field indicating whether the customer wishes to be on a mailing list. Write one or more constructors and the appropriate mutator and...
JAVA/Netbeans •Design a class named Person with fields for holding a person’s name, address and phone...
JAVA/Netbeans •Design a class named Person with fields for holding a person’s name, address and phone number (all Strings) –Write a constructor that takes all the required information. –Write a constructor that only takes the name of the person and uses this to call the first constructor you wrote. –Implement the accessor and mutator methods. Make them final so subclasses cannot override them –Implement the toString() method •Design a class named Customer, which extends the Person class. It should have...
Design a class named Employee. The class should keep the following information in fields: ·         Employee...
Design a class named Employee. The class should keep the following information in fields: ·         Employee name ·         Employee number in the format XXX–L, where each X is a digit within the range 0–9 and the L is a letter within the range A–M. ·         Hire date Write one or more constructors and the appropriate accessor and mutator methods for the class. Next, write a class named ProductionWorker that inherits from the Employee class. The ProductionWorker class should have fields...
Design a class named Employee. The class should keep the following information in fields: ·         Employee...
Design a class named Employee. The class should keep the following information in fields: ·         Employee name ·         Employee number in the format XXX–L, where each X is a digit within the range 0–9 and the L is a letter within the range A–M. ·         Hire date Write one or more constructors and the appropriate accessor and mutator methods for the class. Next, write a class named ProductionWorker that inherits from the Employee class. The ProductionWorker class should have fields...
Question(Design Java Method). There is a java code what created a "Student" class and hold all...
Question(Design Java Method). There is a java code what created a "Student" class and hold all the books owned by the student in the inner class "Book". Please propose a new method for the Student class so that given a Student object "student", a program can find out the title of a book for which student.hasBook(isbn) returns true. Show the method code and the calls to it from a test program. The Student class is following: import java.lang.Integer; import java.util.ArrayList;...
In Java, design a class named MyInteger. The class contains: An int data field named value...
In Java, design a class named MyInteger. The class contains: An int data field named value that stores the int value represented by this object. A constructor that creates a MyInteger object for the specified int A get method that returns the int Methods isEven(), isOdd(), and isPrime() that return true if the value is even, odd, or prime, respectively. Static methods isEven(int), isOdd(int), and isPrime(int) that return true if the specified value is even, odd, or prime, respectively. Static...
Put In Java Programming The TicketMachine class: Design a class named TicketMachine that contains: • A...
Put In Java Programming The TicketMachine class: Design a class named TicketMachine that contains: • A double data field named price (for the price of a ticket from this machine). • A double data field named balance (for the amount of money entered by a customer). • A double data field named total (for total amount of money collected by the machine). • A constructor that creates a TicketMachine with all the three fields initialized to some values. • A...
PUT IN JAVA PROGRAMMING The Stock class: Design a class named Stock that contains: • A...
PUT IN JAVA PROGRAMMING The Stock class: Design a class named Stock that contains: • A string data field named symbol1 for the stock’s symbol. • A string data field named name for the stock’s name. • A double data field named previousClosingPrice that stores the stock price for the previous day. • A double data field named currentPrice that stores the stock price for the current time. • A constructor that creates a stock with the specified symbol and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT