0% found this document useful (0 votes)
5 views

Lab05-OOP

Uploaded by

margenmohamed
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Lab05-OOP

Uploaded by

margenmohamed
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Umm Al-Qura university

Computer & Information Systems


college Instructor: Dr. Aymen M.
Akremi
Lab 05: Object Oriented
Objectives:
programming
- Applying OOP concepts in Java.
- Implementing some inheritance concepts in Java.

Excercise1:
1- Create a super class called Car. The Car class has the following fields and methods:

int speed;
double regularPrice;
String color;

Car (speed, regularPrice, color)


double getSalePrice();

2- Create a subclass of Car class and name it as Sedan. The Sedan class has the following
fields and methods:

int length;

Sedan (speed, regularPrice, color, length)


double getSalePrice();
( If length>20feet, 5%discount will be applied on the sale price, Otherwise, the
discount will be 10%. )

3- Create a sub class of Car class and name it as Truck. The Truck class has the following
fields and methods:

int weight;

Truck (speed, regularPrice, color, weight)


double getSalePrice();
(If weight>2000, 10% discount on the sale price will be applied.)

4- Create a subclass of Sedan class and name it as HondaSedan. The HondaSedan class has
the following fields and methods:

int year;
int manufacturerDiscount; //fixed amount, NOT a percentage

HondaSedan (speed, regularPrice, color, length, year, manufacturerDiscount)


double getSalePrice();
(From the sale price computed from Sedan class, subtract the manufacturer
Discount.)
5- Create a subclass of Truck class and name it as GMCTruck. The GMCTruck class has
the following fields and methods:

int year;
int manufacturerDiscount; //fixed amount, NOT a percentage

GMCTruck (speed, regularPrice, color, weight, year, manufacturerDiscount)


double getSalePrice();
(From the sale price computed from Truck class, subtract the manufacturer
Discount.)

6- Create MyOwnAutoShop class which contains the main() method. Perform the
following within the main() method:

i) Create an instance of Car class and initialize all the fields with appropriate values.

ii) Create an instances of the Sedan class and initialize all the fields with appropriate
values.

iii) Create two instances of the Truck class and initialize all the fields with appropriate
values.

iv) Create an instance of HondaSedan class and initialize all the fields with appropriate
values.

v) Create an instance of GMCTruck class and initialize all the fields with appropriate
values.

vi) Display sale prices for all instances.

You might also like