Write an abstract class called Staff Member that has two protected String fields
ID: 3807973 • Letter: W
Question
Write an abstract class called Staff Member 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 to String method that returns a String with the two values. And include an abstract method in this class called pay() that returns a double. 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 pay() method that just returns the value of zero, and it has a toString() method that returns the String "Volunteer: " followed by what the toString() method of the parent class returns.Explanation / Answer
Below is the 2 class files according to the question,
StaffMember.java
public abstract class StaffMember {
protected String name;
protected String phone;
public StaffMember(String name, String phone){
this.name=name;
this.phone=phone;
}
public abstract double Pay();
@Override
public String toString() {
return String.format("%s %s", name, phone);
}
}
Volunteer.java
public class Volunteer extends StaffMember {
public Volunteer(String name,String phone) {
super(name,phone);
// TODO Auto-generated constructor stub
}
@Override
public double Pay() {
// TODO Auto-generated method stub
return 0;
}
public String toString() {
return String.format("Volunteer :"+"%s %s", super.name, super.phone);
}
}
!! Have a good Day !!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.