Question: Write classes that could be used in a system that manages vehicles in a public transportation system. You will write classes to represent a TransitVehicle,

Write classes that could be used in a system that manages vehicles in a public transportation system.
You will write classes to represent a TransitVehicle, Bus, and SubwayCar. The information about the classes is below.
Step 1: Plan Your Class Design
Before you start to code, decide how to design your classes. Which class should be the parent? the child? What variables or methods belong in each class?
Step 2: Write the Core Class Components (12 points)
Write the three classes. Each class must have all of the following.
Important: a class can have a method directly (meaning written into the code) or indirectly (meaning inherited from a parent). Either of these counts to meet the requirement.
instance data variables
transit vehicles are described by an id that contains letters and numbers and a description of the routebuses are described by an id, route, and the number of miles per gallon (without decimals)subway cars are described by an id, route, and whether or not the car goes underground
a constructor that sets all of the instance data variables using parameters
getter and setter methods
in your setter for the number of miles per gallon, use validity checking to make sure the parameter is valid before assigning it to the instance data variable
a toString method
formatting of the text representation is provided below in the expected outputinclude the route and id for all vehiclesfor buses, also include the word "Bus" and the miles per gallonfor subway cars, also include the words "Subway" and add a notation if the car goes underground
Step 3: Class Specific Methods (4 points)
Write three class specific methods. Decide which class each method belongs in. If a method is in a parent class, decide if it also needs to be overridden in the child class.
printSchedule
all transit vehicles display their route and id (no actual schedule needs to be shown)
repair
all transit vehicles display a message that they need repair; the message includes their idfor subway cars that go underground, the message also includes a note that the car must be removed from the tunnel
fuel
buses display a message that they are being given fuel; the message includes the bus id
Step 4: Write a Driver Program (4 points)
Write code in a main method to demonstrate your classes. In main:
Create a list of transit vehicles using the data below.
Iterate the list and print the text representation of each vehicle.
Iterate the list and print the schedule for each vehicle.
Iterate the list and repair each vehicle.
The expected output is shown below.
Design and Additional Coding Requirements (5 points)
code should compile
the inheritance relationship and method placement should be a logical fit for the classes
follow best practices related to inheritance, including letting a parent class be in charge of parent functionality (e.g., by using super(...) and super.method(...))
reduce duplicated code (consider how to replace repeated code with a method or through inheritance)
follow Java naming conventions for classes (upper camel case) and for variables and methods (lower camel case with no underscores)
choose the best loops and conditional structures for a task
use constants instead of hard-coded values when possible to improve clarity and readability and to make code easier to maintain
Transit Vehicle Data
Bus: route = "Fulton St 5", id ="F12", bus gets 4 miles to the gallon
Bus: route = "Geary St 38", id ="G43", bus gets 3 miles to the gallon
Bus: route = "Geary St 38L", id ="G92", bus gets 7 miles to the gallon
Subway Car: route = "Judah St N", id ="J19", does not go underground
Subway Car: route = "Taraval L", id ="T25", goes underground

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!