In: Computer Science
package dealership; public abstract class Vehicle { private float dealerPrice; private int year; public Vehicle(float d, int y) { dealerPrice = d; year = y; }
public float getDealerPrice() { return dealerPrice; } public int getYear() { return year; }
public abstract float getStickerPrice();
}
In the space below write a concrete class Car in the dealership package that is a subclass of Vehicle class given above.
You will make two constructors, both of which must call the superclass constructor. Make a two argument constructor (float, int) that initializes both instance variables using the arguments (think carefully about how this should be done). Make a single argument constructor (float) that initializes the dealerPrice with the float argument and initializes year to the current year (2020). Override the getStickerPrice()method so that it returns 1.5 times the dealerPrice if the year is at least 2010, and returns 1.2 times the dealerPrice if the year is older than 2010 (that is, year < 2010).
Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions. Thank You! =========================================================================== package dealership; public class Car extends Vehicle { //that initializes the dealerPrice with the float argument and initializes year to the current year (2020 public Car(float price) { super(price, 2020); } //Make a two argument constructor (float, int) that initializes both instance variables public Car(float price, int year) { super(price, year); } public float getStickerPrice() { if (getYear() >= 2010) return (float) (1.5 * super.getDealerPrice()); else return (float) (1.2 * super.getDealerPrice()); } }
====================================================================