public class RentalApt extends Apartment{
private String tenant;
private boolean rented;
public RentalApt(String owner, int size, boolean rented, String who){
super(owner,size);
tenant = who;
this.rented = rented;
}
public boolean getRented(){
return rented;
}
public String getTenant(){
return tenant;
}
public void setRented(boolean isRented){
rented = isRented;
}
public void setTenant(String who){
tenant= who;
}
public String toString(){
String s = super.toString();
return (s + " occupied? " + rented + " tenant: " + tenant);
}
}
Suppose you create a new PricedApt class that is derived from the RentalApt class (so it's derived from a derived class). It adds one new double attribute, price, which tells what the monthly rental for the apartment is. Here is a constructor call for the class:
PricedApt p = new PricedApt("jill", 900, true, "jack", 1050.00);
Using super appropriately, write a toString method for the class which, in addition to telling about jill as owner and jack as tenant, adds to the toString output the phrase " price: " + price. (Note: a super call to toString in PricedApt will use the toString method from its base class, RentalApt.
public class PricedApt extends RentalApt {
private double price;
public String toString() {
//code
So I know that I need to recycle the toString() method in RentalApt, but I'm getting an error with rented and tenant, as they are private. I've tried everything I know, but I haven't managed to get past that error. Here's what I have so far:
public String toString() {
String s = super.toString();
return (s + " occupied? " + rented + " tenant: " + tenant+ " price: " + price);
}
I've tried some things with the keyword super, but nothing successful. Sorry for this question: I know it's been answered before, but nothing I've seen from past answers solved my elementary problem.