-
Complete the
Car.java
class so that it meets the following requirements: -
Every
Car
object should know itsmake
(a String),model
(a String),fuelMileage
(a double),numberOfDoors
(an int) and itstopSpeed
(an int). -
Create a default constructor that is not passed any parameters. A default
Car
should have a make and model of"Generic"
fuel mileage of 25.5 miles per gallon, 4 doors and a top speed of 105 miles per hour. -
Create an overloaded constructor that is passed 3 paramaters to initialize the instance variables (in alphabetical order).
-
All instance variables should have appropriately named accessor and mutator methods.
-
Override the
toString
method from theObject
class in the format:Make: Toyota Model: Camry Doors: 4 Fuel Mileage: 34 mpg Top Speed: 115 mph
-
Create a driver program
CarTester.java
to test yourCar
class. Create 3 differentCar
objects, including a defaultCar
. Then print eachCar
using thetoString
method. You should also test your accessor and mutator methods in your driver class. When you test them print the object, mutate a field, then print the field again.
-
Create a
Truck
class that is a subclass of aCar
object. -
A
Truck
should know everything that aCar
knows as well as have a boolean valueisFourWheelDrive
and a feild for itstowingCapacity
(an int). -
Create a default constructor that initializes that leaves all of the default
Car
fields the same other thannumDoors
which should automatically be changed to 2. The defaultTruck
should be 2 wheel drive and have a towing capacity of 6500 pounds. -
Create an overloaded constructor which takes 7 parameters, in alphabetical order to initialize all of the
Truck
fields. -
Override the
toString
method to print theTruck
objects in the formaat:Make: Chevrolet Model: Silverado Doors: 2 Fuel Mileage: 20 mpg Top Speed: 100 mph Four Wheel Drive: true Towing Capacity: 6500 lbs
-
Create a driver program
TruckTester.java
to test yourTruck
class. Create 3 differentTruck
objects, including a defaultTruck
. Then print eachTruck
using thetoString
method. You should also test your accessor and mutator methods in your driver class. When you test them print the object, mutate a field, then print the field again.
-
Create a class called
ParkingLot.java
that has one instance varaiblelot
that is an array that can holdCar
andTruck
objects. The parking lot should only be able to hold up to 20 vehicles. -
Create a class variable
numVehicles
that keeps track of the number of vehicles in the lot. -
Create a default constructor that intializes the
lot
to an empty array with 20 spaces. -
Create a method called
parkVehicle
which excepts aCar
orTruck
object as a parameter and adds that Vehicle to thelot
. It also needs to update the number of vehicles in the lot. This method should never park a vehicle if ther is not a space available to park in. Meaning if the lot is full it should deny parkVehicle and print a message that the lot is full. -
Write a
toString
method for theParkingLot
class that uses a loop to print eachCar
andTruck
in the lot. -
Create a driver class
ParkingLotTester.java
that creates oneParkingLot
object calledberryLot
. -
Manually add the following vehicles to the array (do not use a Scanner):
Make | Model | Doors | Mileage | Top Speed | Four Wheel Drive | Towing Capacity |
---|---|---|---|---|---|---|
Ford | Escort | 4 | 35.2 | 85 | ||
Ford | F250 | 2 | 24.3 | 115 | true | 9000 |
Chevy | Impala | 4 | 27.8 | 120 | ||
Toyota | Corolla | 4 | 38.7 | 100 | ||
Dodge | Ram | 4 | 19.3 | 110 | false | 7000 |
Generic | Generic | 4 | 25.5 | 105 | ||
Generic | Generic | 2 | 25.5 | 105 | false | 6500 |
GMC | Sierra | 4 | 23.1 | 125 | true | 8000 |
- Call
System.out.println(berryLot);
-
Modify the
Car
class so that it implementsComparable
. -
Car
andTruck
objects are only ranked based on their top speed. The lower the top speed, the lower the rank of the vehicle. -
Add the method
sortLot()
to theParkingLot
class. This is a mutator method that sorts thelot
instance variable using one single statement:Arrays.sort(lot);
. -
Make a copy of
ParkingLotTester
and rename itParkingLotTester2
. At the very end of the main method, callberryLot.sortLot()
then callSystem.out.println(berryLot);
once more.