Lab 24

Fleet of Vehicles

 

Objective:

 

Write a classes that represents a vehicle system

 

First download the driver and put it in your project

 

Regarding .equals():  Just go ahead and take a Vehicle/Car/Truck parameter… this is not really the normal way: see https://www.sitepoint.com/implement-javas-equals-method-correctly

 

Write a class file called Vehicle

 

Write another class Truck which is a Vehicle

 

Write another class Car which is a Vehicle

 

Example Dialog:

Welcome to the fleet manager

Enter 1: to add a Vehicle

Enter 2: to remove a Vehicle

Enter 9 to quit

1

Enter 1: if it is a car

Enter 2: if it is a truck

Enter 3: if it is unclassified

1

Enter the manufacturer's name

Nissan

Enter the number of cylinders

6

Enter the owner's name

JJ

Enter the car's gas mileage

29

Enter the number of passengers

5

The Fleet currently

Manufacturer's Name: Nissan

Number Of Cylinders: 6

Owner's Name: JJ

Gas Mileage: 29.0

Number of Passengers: 5

 

Enter 1: to add a Vehicle

Enter 2: to remove a Vehicle

Enter 9 to quit

1

Enter 1: if it is a car

Enter 2: if it is a truck

Enter 3: if it is unclassified

2

Enter the manufacturer's name

Chevy

Enter the number of cylinders

8

Enter the owner's name

Eddie

Enter the truck's load capacity

1

Enter the truck's towing capacity

2

The Fleet currently

Manufacturer's Name: Nissan

Number Of Cylinders: 6

Owner's Name: JJ

Gas Mileage: 29.0

Number of Passengers: 5

 

Manufacturer's Name: Chevy

Number Of Cylinders: 8

Owner's Name: Eddie

Towing Capacity: 2.0

Load Capacity: 1.0

 

Enter 1: to add a Vehicle

Enter 2: to remove a Vehicle

Enter 9 to quit

1

Enter 1: if it is a car

Enter 2: if it is a truck

Enter 3: if it is unclassified

3

Enter the manufacturer's name

Ford

Enter the number of cylinders

6

Enter the owner's name

Bob

The Fleet currently

Manufacturer's Name: Nissan

Number Of Cylinders: 6

Owner's Name: JJ

Gas Mileage: 29.0

Number of Passengers: 5

 

Manufacturer's Name: Chevy

Number Of Cylinders: 8

Owner's Name: Eddie

Towing Capacity: 2.0

Load Capacity: 1.0

 

Manufacturer's Name: Ford

Number Of Cylinders: 6

Owner's Name: Bob

 

Enter 1: to add a Vehicle

Enter 2: to remove a Vehicle

Enter 9 to quit

2

Enter 1: if it is a car

Enter 2: if it is a truck

Enter 3: if it is unclassified

2

Enter the manufacturer's name

Chevy

Enter the number of cylinders

8

Enter the owner's name

Eddie

Enter the truck's load capacity

1

Enter the truck's towing capacity

2

The Fleet currently

Manufacturer's Name: Nissan

Number Of Cylinders: 6

Owner's Name: JJ

Gas Mileage: 29.0

Number of Passengers: 5

 

Manufacturer's Name: Ford

Number Of Cylinders: 6

Owner's Name: Bob

 

Enter 1: to add a Vehicle

Enter 2: to remove a Vehicle

Enter 9 to quit

9

The Fleet currently

Manufacturer's Name: Nissan

Number Of Cylinders: 6

Owner's Name: JJ

Gas Mileage: 29.0

Number of Passengers: 5

 

Manufacturer's Name: Ford

Number Of Cylinders: 6

Owner's Name: Bob

 

Goodbye

Lab Report Questions:

  1. Describe inheritance.
  2. Describe polymorphism.

Finally:

Upload file to the dropbox