Lab 08

Fleet of Vehicles

 

Objective:

 

Use classes and inheritance to create a vehicle system managing system.

 

 

Lab Solution

 

Requirements: 

Manufacturer’s Name: <<Manufacturer’s Name>>\n

Number of Cylinders: <<Number of Cylinders>>\n

Owner’s Name: <<Owner’s Name>>\n

Where values in “<<>>” correspond to the instance variable values.

Manufacturer’s Name: <<Manufacturer’s Name>>\n

Number of Cylinders: <<Number of Cylinders>>\n

Owner’s Name: <<Owner’s Name>>\n

Towing Capacity: <<Towing Capacity>>\n

Load Capacity: <<Load Capacity>>\n

Where values in “<<>>” correspond to the instance variable values.

Manufacturer’s Name: <<Manufacturer’s Name>>\n

Number of Cylinders: <<Number of Cylinders>>\n

Owner’s Name: <<Owner’s Name>>\n

Gas Mileage: <<Gas Mileage>>\n

Number of Passengers: <<Number of Passengers>>\n

Where values in “<<>>” correspond to the instance variable values.

 

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

QWERTY

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: QWERTY

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

ASDF01

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: QWERTY

Gas Mileage: 29.0

Number of Passengers: 5

 

Manufacturer's Name: Chevy

Number Of Cylinders: 8

Owner's Name: ASDF01

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

ASDF02

The Fleet currently

Manufacturer's Name: Nissan

Number Of Cylinders: 6

Owner's Name: QWERTY

Gas Mileage: 29.0

Number of Passengers: 5

 

Manufacturer's Name: Chevy

Number Of Cylinders: 8

Owner's Name: ASDF01

Towing Capacity: 2.0

Load Capacity: 1.0

 

Manufacturer's Name: Ford

Number Of Cylinders: 6

Owner's Name: ASDF02

 

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

ASDF01

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: QWERTY

Gas Mileage: 29.0

Number of Passengers: 5

 

Manufacturer's Name: Ford

Number Of Cylinders: 6

Owner's Name: ASDF02

 

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: QWERTY

Gas Mileage: 29.0

Number of Passengers: 5

 

Manufacturer's Name: Ford

Number Of Cylinders: 6

Owner's Name: ASDF02

 

Goodbye

 

 

Solution Tests:

  1. Is your name written as a comment in all source files?
  2. Does the solution compile (no syntax errors)?

3.      Does your output match the example dialog?

 

Lab Report

  1. Create a section named “Problem” and describe this lab’s problem in your own words. (10pts).
  2. Create a section named “Solution Description” and describe how the code solves the problem in your own words. (10pts).
  3. Create a section named “Problems Encountered” and describe the various syntax, run-time, and logic errors that were encountered while implementing the solution. (10pts).
  4. Describe inheritance in OOP. (10pts).
  5. When creating a class, what reserved word in Java creates the inheritance, “is a” relationship? (10pts).
  6. When calling a method or accessing a property from an inherited / “parent” class, what reserved word in Java must be called? (10pts).
  7. Is it possible to call a private method or access a private property from an inherited class? (10pts).
  8. In Java, is it possible to inherit from multiple classes? (10pts).
  9. Assuming that we have Classes “ParentClass” and “ChildClass”, where “ChildClass” inherits from “ParentClass”. Would the following code work without error? If there is an error explain why and how it can be fixed.

  1. Assuming that we have Classes “ParentClass” and “ChildClass”, where “ChildClass” inherits from “ParentClass”. Would the following code work without error? If there is an error explain why and how it can be fixed.

 

 

Finally:

Upload the source code (.JAVA File Extension) and written lab report (.DOC, .DOCX, or .PDF file extension) to the CSCE Dropbox.