Answered step by step
Verified Expert Solution
Question
1 Approved Answer
in java SUMMARY Make a java application that creates vehicle objects using an inheritance class hierarchy and is able to start and stop them based
in java
- SUMMARY
- Make a java application that creates vehicle objects using an inheritance class hierarchy and is able to start and stop them based on user requests.
- This lab will involve the following new features:
- Inheritance.
- DETAILS
- Classes
- MotorVehicle
- Declare at least two instance variables in the MotorVehicle class that each child class (Motorcycle and Car) will inherit.
- One instance variable must be a boolean that is called "running".
- The other instance variable is up to you... "color", "make", etc.
- Motorcycle and Car
- Have them inherit from MotorVehicle.
- Declare one instance variable in each of these classes that is unique to the type.
- For example, you could put a "doorCount" int variable in the Car class and a "windshield" boolean variable into the Motorcycle class.
- In the Motorcycle and Car classes, make two methods in each: start and stop methods.
- The start and stop methods will first change the "running" variable.
- In the start method, set the running variable to true.
- In the stop method, set the running variable to false.
- The start and stop methods will then print to the screen:
- The class's two inherited instance variable values.
- The specific class's instance variable value (such as "doorCount" for the Car class).
- What type of vehicle it is (Motorcycle or Car).
- Whether it's been stopped or started.
- The start and stop methods will first change the "running" variable.
- VehicleManager
- Two instance variables that are arrays, one of Car array type and one of Motorcycle array type.
- A "run" method that does the following:
- Instantiates three objects of Car type and three of Motorcycle type.
- Sets the "running" variable on each to false.
- Fills the other instance variables on each object directly in code with any value you wish.
- So if you had "color" as a variable of String type in MotorVehicle, set one to "red", one to "green", etc.
- Put all the objects into the two arrays mentioned above.
- (car objects in cars array, motorcycle objects in motorcycles array)
- Then displays a series of things to the user with the following flow:
- First a menu for choosing which car to START:
- Lists the cars with numbers and asks which one to start.
- Use 1 to 3 as menu item numbers instead of 0 to 2.
- When item # chosen, then the start method for that object is called.
- The number they enter has to be adjusted for the correct array index obviously.
- Lists the cars with numbers and asks which one to start.
- Second is the menu for which motorcycle to START:
- Same as above except now for the motorcycle array.
- Third is the menu for which car to STOP:
- Same as the ones above except now the stop method is being called instead of start.
- Fourth is the menu for which motorcycle to STOP.
- Same as above, but now for motorcycle.
- Fifth, display all 6 vehicles status on whether they're running or not.
- Vehicle_Test
- Put the main method here.
- In the method, simply instantiate an instance of VehicleManager and call its run method.
- Put the main method here.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started