Question

For task 2, implement the three classes (Person, Student, and Staff) that are described above. Note...

For task 2, implement the three classes (Person, Student, and Staff) that are described above. Note that classes Staff and Student are derived from the superclass Person -- in other words Staff and Student inherit from Person. Make sure that the subclasses Student and Staff invoke the superclass' constructors and correctly inherit the variables and methods from the superclass Person. Also note that Person is an abstract class.

<abstract> Person

-name:String

-address:String = “String”

+getName():String

+getAddress():String

+setAddress(address:String):void

+setName(name:String):void

Staff

-school:String

-pay:double

+Staff(name:String, address:String, pay:double)

+getSchool():String

+setSchool(school:String):void

+getPay():double

+setPay(pay:double):void

+toString():String

Student

-program:String

-year:int

-fee:double

+Student(name:String, address:String, program:String, year:int, fee:double)

+getProgram():String

+setProgram(program:String):void

+getYear():int

+setYear(year:int):void

+getFee():double

+setFee(fee:double):void

+toString():String

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

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

// Person.java

public abstract class Person {
   //Declaring instance variables
   private String name;
   private String address = "String";

   // getters and setters
   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;
   }

}
_____________________

// Student.java

public class Student extends Person {

   //Declaring instance variables
   private String program;
   private int year;
   private double fee;

   //Parameterized constructor
   public Student(String name, String address, String program, int year,
           double fee) {
       setName(name);
       setAddress(address);
       this.program = program;
       this.year = year;
       this.fee = fee;
   }

   // getters and setters
   public String getProgram() {
       return program;
   }

   public void setProgram(String program) {
       this.program = program;
   }

   public int getYear() {
       return year;
   }

   public void setYear(int year) {
       this.year = year;
   }

   public double getFee() {
       return fee;
   }

   public void setFee(double fee) {
       this.fee = fee;
   }

   //toString method is used to display the contents of an object inside it
   @Override
   public String toString() {
       return "Student [Name = " + getName() + ", Address =" + getAddress()
               + ", Program=" + program + ", Year=" + year + ", Fee=" + fee
               + "]";
   }

}
__________________________

// Staff.java

public class Staff extends Person {
   //Declaring instance variables
   private String school;
   private double pay;

   //Parameterized constructor
   public Staff(String name, String address, String school, double pay) {
       setName(name);
       setAddress(address);
       this.school = school;
       this.pay = pay;
   }

   // getters and setters
   public String getSchool() {
       return school;
   }

   public void setSchool(String school) {
       this.school = school;
   }

   public double getPay() {
       return pay;
   }

   public void setPay(double pay) {
       this.pay = pay;
   }

   //toString method is used to display the contents of an object inside it
   @Override
   public String toString() {
       return "Staff [Name = " + getName() + ", Address =" + getAddress()
               + ", School=" + school + ", Pay=" + pay + "]";
   }

  
}
__________________________

// Test.java

public class Test {

   public static void main(String[] args) {
Staff s=new Staff("Williams","12,Church Street,Mumbai","Little Flower",54000);
Student st=new Student("Ben","23,Lake View Street,Calcutta","Self Learning", 2018,34000);
System.out.println(s);
System.out.println(st);
  

   }

}
___________________________

Output:

Staff [Name = Williams, Address =12,Church Street,Mumbai, School=Little Flower, Pay=54000.0]
Student [Name = Ben, Address =23,Lake View Street,Calcutta, Program=Self Learning, Year=2018, Fee=34000.0]


_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
For task 2, implement the three classes (Person, Student, and Staff) that are described above. Note...
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
  • Implement a superclass Person. Make two classes, Student and Instructor, that inherit from Person. A person...

    Implement a superclass Person. Make two classes, Student and Instructor, that inherit from Person. A person has a name and a year of birth. A student has a major, and an instructor has a salary. Writhe the class definitions, the constructors, and the methods toString for all classes. For Person the constructors should include a no-arg constructor and one that accepts in the name of the person. For student there should be a no-arg constructor and a constructor that accepts...

  • Implement an abstract class named Person and two subclasses named Student and Staff in Java. A person has a name, address, phone number and e-mail address. A student has a credit hour status (freshman...

    Implement an abstract class named Person and two subclasses named Student and Staff in Java. A person has a name, address, phone number and e-mail address. A student has a credit hour status (freshman, sophomore, junior, or senior). Define the possible status values using an enum. Staff has an office, salaray, and date-hired. Implement the above classes in Java. Provide Constructors for classes to initialize private variables. Getters and setters should only be provided if needed. Override the toString() method...

  • a c++ program (The Person, Student, Employee, Faculty, and Staff classes) Design a class named Person...

    a c++ program (The Person, Student, Employee, Faculty, and Staff classes) 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 MyDate classto create an object for date hired. A faculty...

  • Design a class named Person and its two derived classes named Student and Employee. MakeFaculty and Staff derived classes of Employee

    In Java(The Person, Student, Employee, Faculty, and Staff classes)Design a class named Person and its two derived classes named Student and Employee. MakeFaculty and Staff derived classes of Employee. A person has a name, address, phone number, and e-mail address. A student has a class status (freshman, sophomore, junior, or senior). An employee has an office, salary, and date hired. Define a class namedMyDate that contains the fields year, month, and day. A faculty member has office hours and a rank....

  • How to create a constructor that uses parameters from different classes? I have to create a...

    How to create a constructor that uses parameters from different classes? I have to create a constructor for the PrefferedCustomer class that takes parameters(name, address,phone number, customer id, mailing list status, purchase amount) but these parameters are in superclasses Person and Customer. I have to create an object like the example below....... PreferredCustomer preferredcustomer1 = new PreferredCustomer("John Adams", "Los Angeles, CA", "3235331234", 933, true, 400); System.out.println(preferredcustomer1.toString() + "\n"); public class Person { private String name; private String address; private long...

  • Introduction In this lab, you will be working with three classes: Person, Student, and Roster. Person...

    Introduction In this lab, you will be working with three classes: Person, Student, and Roster. Person and Student represent individuals with a first and last name as String class variables, and Student has an additional int class variable that represents a ID number. The Roster class represents a group of people that are objects of either the Person or Student class. It contains an ArrayList. The Person class has been completed for you with class variables, a constructor, and a...

  • This is the question about object-oriend programming(java) please show the detail comment and prefect code of...

    This is the question about object-oriend programming(java) please show the detail comment and prefect code of each class, Thank you! This question contain 7 parts(questions) Question 1 Create a class a class Cat with the following UML diagram: (the "-" means private , "+" means public) +-----------------------------------+ | Cat | +-----------------------------------+ | - name: String | | - weight: double | +-----------------------------------+ | + Cat(String name, double weight) | | + getName(): String | | + getWeight(): double | |...

  • Required in Java. Thank you. 1. Create a base class called Vehicle that has the manufacturer's...

    Required in Java. Thank you. 1. Create a base class called Vehicle that has the manufacturer's name (type String), number of cylinders in the engine (type int), and owner (type Person given in Listing 8.1 in the textbook and in LMS). Then create a class called Truck that is derived from Vehicle and has additional properties: the load capacity in tons (type double, since it may contain a fractional part) and towing capacity in tons (type double). Give your classes...

  • Java: student directory GUI You need to implement three classes: Person Student StudentDirectory StudentMain Start by...

    Java: student directory GUI You need to implement three classes: Person Student StudentDirectory StudentMain Start by implementing Person and Student classes. Once you are sure you can serialize and deserialize and ArrayList of Students to and from a file, move on to building the GUI application. Person: The Person class should implement serializable interface. It contains the following: Person's first name (String) Person's last name (String) Person's id number Person's date of birth (Date) public String toString(): This method method...

  • Please provide the code for the last part(client side program). yes i have all the class...

    Please provide the code for the last part(client side program). yes i have all the class implementations. ``` person.h #ifndef PERSON_H #define PERSON_H #include <string> using namespace std; class person { public: person(); string getname() const; string getadd() const; string getemail() const; string getphno() const; string toString() const; private: string name; string add; string email; string phno; }; ```person.cpp #include "person.h" person::person() { name = "XYZ"; add="IIT "; email="%%%%"; phno="!!!!!"; } string person::getname() const { return name; } string person::getadd()...

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