Question: Write a superclass called Person (as shown in the class diagram), which contains: Two instance variables name (String) and address (String). Two constructors: a (no-argument)

Write a superclass called ؛Person (as shown in the class diagram), which contains:

  • Two instance variables name (String) and address (String).
  • Two constructors: a (no-argument) constructor that initializes the name to "Ahmed" and address to “Gaza”, and a constructor that initializes the name and address to the given values.
  • Getter and setter for all the instance variables.
  • A toString() method that returns "A Person with name of xxx and address of yyy

Write a test program to test all the methods defined in Person.

Write two subclasses of Person called Student and Staff, as shown in the class diagram.

The Student class contains:

  • An instances variable program (String), year(int) and fee(double) .
  • One constructor as shown.
  • Getter and setter for the instances variable program , year and fee.
  • Override the toString() method inherited, to return "A  Student  with  [name,address]

,[program,year  and  fee].

The Staff class contains:

  • Two instance variables school (String) and pay (double).
  • One constructor as shown.
  • Getter and setter for all the instance variables.
  • Override the toString() method inherited, to return "A  Staff  [name,address],[school,pay]

Ex: Superclass Person and its subclasses Student and Staff

Person |-name:String -address:String +Person (name: String, address:String) +getName ():String +getAddress():String +setAddress (address:String)


 

Person |-name:String -address:String +Person (name: String, address:String) +getName ():String +getAddress():String +setAddress (address:String) : void +tostring():String "Person[name=?, address=?]" extends Student Staff -program:String -year:int |-fee:double -school:String -pay: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 . +Staff(name:String, address:String, school:String,pay:double) +getSchool ():String +setSchool (school:String):void +getPay(): double +setPay (pay:double):void +toString():String "Staff[Person[name=?, address=?], school=?, pay=?]" "Student[Person[name=?, address=?], program-?, year=?, fee=?]" %3D

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Personjava public class Person public String name public String address public PersonString nString ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!