1. Write an abstract class called StaffMember that has two protected String fiel
ID: 3911795 • Letter: 1
Question
1. Write an abstract class called StaffMember that has two protected String fields called name and phone, and it also has a two argument constructor that sets those two fields. Don't worry about creating getters and setters for those field values, but you must create a toString method that returns a String with the two values. And include an abstract method in this class called pay0 that returns a double. 2. After writing that class, write another class called Volunteer, which inherits from the StaffMember class and has no additional fields. The Volunteer class has a two argument constructor that sets the two field values of its parent class, and it has a pay0 method that just returns the value of zero, and it has a toString0 method that returns the String "Volunteer:" followed by what the toString0 method of the parent class returns.Explanation / Answer
StaffMember.java
***************************
public abstract class StaffMember {
protected String name, phone;
public StaffMember(String name, String phone) {
super();
this.name = name;
this.phone = phone;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "StaffMember [name=" + name + ", phone=" + phone + "]";
}
public abstract double pay();
}
Volunteer.java
****************************
public class Volunteer extends StaffMember{
public Volunteer(String name, String phone) {
super(name, phone);
}
@Override
public double pay() {
return 0;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Volunteer : " + super.toString();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.