Exercises3-Java-Inheritance and Polymorphism
Exercises3-Java-Inheritance and Polymorphism
int speed;
double regularPrice;
string color;
double getSalePrice();
b. Create a sub class of Car class and name it as Truck. The Truck class has the following
fields and methods:
int weight;
double getSalePrice();//Ifweight>2000,10%discount.Otherwise,20%discount.
c. 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 sale price computed from Car class , subtract the
manufacturerDiscount.
d. Create a subclass of Car class and name it as Sedan. The Sedan class has the following
fields and methods:
int length;
double getSalePrice();//Iflength>20feet,5%discount,Otherwise,10%discount.
e. 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. Use super(...) method in the constructor for initializing the fields of the
superclass.
Create two instances of the Ford class and initialize all the fields with appropriate
values. Use super(...) method in the constructor for initializing the fields of the
super class.
Create an instance of Car class and initialize all the fields with appropriate values.
Display the sale prices of all instance.
Ex 2. Write an applet that asks the user to enter two floating ‐point numbers, obtains the
two numbers from the user and draws their sum, product (multiplication), difference and
quotient (division). Use the techniques shown in example.