banner

Thursday, September 29, 2016

PE8: Inheriting the Car Class

a) Create a super class called Car . The Car class has the following fields and methods. int speed; double regularPrice; String c... thumbnail 1 summary

a) Create a super class called Car. The Car class has the following fields and methods.

  • int speed;
  • double regularPrice;
  • String color;
  • double getSalePrice();

b) Create a subclass of Car class and name it as Ford. The Ford class has the following fields and methods

  • int year;
  • int manufacturerDiscount;
  • double getSalePrice(); //From the salepricecomputed from Car class, subtract the manufacturerDiscount.

c) Create a subclass of Car class and name it as Sedan. The Sedan class has the following fields and methods.

  • int length;
  • double getSalePrice(); //If length >20feet, 5% discount,Otherwise,10% discount.

d) Create MyOwnAutoShop class which contains the main() method. Perform the following within the main() method.
  • Create an instance of Sedan class and initialize all the fields with appropriate values. 
  • Create two instances of the Ford class and initialize all the fields with appropriate values. 
  • Create an instance of a Car class and initialize all the fields with appropriate values.
  • Display the sale prices of all instance.
// Note : Use this and Super() wherever applicable

No comments

Post a Comment