Suppose you create a new PricedApt class that is derived from the RentalApt clas
ID: 3566332 • Letter: S
Question
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 toStringmethod from its base class, RentalApt.
public class PricedApt extends RentalApt {
private double price;
//constructor goes here
public String toString() {
CODE GOES HERE
} //end method
} //end class
Explanation / Answer
public class PricedApt extends RentalApt {
private double price;
//constructor goes here
PricedApt(String owner, int code, boolean isAvailable, String tenant, double price)
{
super(owner, code, isAvailable, tenant);
this.price = price;
}
public String toString()
{
CODE GOES HERE
// calls the base class toString()
return ""+super.toString()+" price : "+price;
} //end method
} //end class
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.