CSI 311L Lab 9, Spring 2012
American University of Science and Technology · Java Programming Laboratory · 3 pages · Dr. Saeed Raheel
More CSI 311L files
Show the text of this lab
American University of Science & Technology
Department of Computer Science
CSI 311L – Java Programming Lab
Spring 2011/2012
Lab Work 9
Problem1:
Write the classes implementations for the following class specifications.
Registered_Vehicle
Attribute
s
Year: an integer to indicate the registration year.
Plnum: A String to indicate the license_plate number.
type: an integer that can have the value 1(private) or 2(public).
Methods
Constructor .
toString: to return the information about a Registered vehicle
as follows:
(08)-(123456) was registered in 1994 and is a private
vehicle.
Get_type: returns the type of a registered vehicle.
Remark
All attributes should be declared private
1
Write an application to test your classes’ implementations.
2
Car
Note that all cars are registered vehicles.
Attributes
Brand: a string of characters to store the car
brand name.
Color: a string of characters.
Model: an integer to specify the car model number.
Cost: a number to indicate the car basic cost.
Totalprice: It should accumulate the value of all cars’ prices.
Methods
Constructor.
Calculate_price: return the price of a car using the following
Formula:
Price = cost + 300$ if the type = 1.
Price = cost + 200$ if type =2.
Get_totalprice: returns the value of Totalprice.
display: to print the information about a car as follows:
Mercedes-red-300
(08)-(123456) was registered in 1994 and is a private vehicle.
Price = $12500.
Problem 2:
A. Implement, in Java, the following classes:
Bicycle
Attributes
gear: an integer (from 1 to 5) to specify the gear of the bicycle
cost: an integer to specify the basic cost of the bicycle
count: to count the number of bicycles
Methods
Constructor
set and get methods
toString: to return information about a bicycle
computePrice: returns the price of the bicycle by adding to the cost:
$10 for each level of gear
MountainBike (a bicycle)
Attributes
suspension: a String that has the value “Front” if the bike has a front
shock absorber or “Dual” if the bike has a front and back shock absorber.
Methods
Constructor
set and get methods
toString: to return information about a bike
computePrice: returns the price of the bike by adding to price of a
bicycle:
$100 if the bike has “Front” suspension
$150 if the bike has “Dual” suspension
B. Write a java application to do the following (Use JOptionPane methods):
Create N objects of class MountainBike and let the user initialize them
Display the total number of all bicycles
Display information about all mountain bikes with dual suspension
3