Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA Lab 1 NOTE : For this lab, you will get 5 points for a valid attempt if turned in by the due date. The

JAVA

Lab 1

NOTE: For this lab, you will get 5 points for a valid attempt if turned in by the due date.

The main new component in this lab, inheritance, is in Chapter 2 and were reviewed in class.

TIP: Remember, don't be overwhelmed by all the details. Simply focus on one line at a time as the instructions walk you through the creation of the app.

  1. SUMMARY

  1. 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.

  1. This lab will involve the following new features:
    1. Inheritance.

  1. DETAILS

  1. Classes

  1. MotorVehicle

  1. Declare at least two instance variables in the MotorVehicle class that each child class (Motorcycle and Car) will inherit.

  1. One instance variable must be a boolean that is called "running".
  2. The other instance variable is up to you... "color", "make", etc.

  1. Motorcycle and Car

  1. Have them inherit from MotorVehicle.

  1. Declare one instance variable in each of these classes that is unique to the type.
    1. For example, you could put a "doorCount" int variable in the Car class and a "windshield" boolean variable into the Motorcycle class.

  1. In the Motorcycle and Car classes, make two methods in each: start and stop methods.
    1. The start and stop methods will first change the "running" variable.
      1. In the start method, set the running variable to true.
      2. In the stop method, set the running variable to false.
    2. The start and stop methods will then print to the screen:
      1. The class's two inherited instance variable values.
      2. The specific class's instance variable value (such as "doorCount" for the Car class).
      3. What type of vehicle it is (Motorcycle or Car).
      4. Whether it's been stopped or started.

  1. VehicleManager

  1. Two instance variables that are arrays, one of Car array type and one of Motorcycle array type.

  1. A "run" method that does the following:

  1. Instantiates three objects of Car type and three of Motorcycle type.
  2. Sets the "running" variable on each to false.
  3. Fills the other instance variables on each object directly in code with any value you wish.
    1. So if you had "color" as a variable of String type in MotorVehicle, set one to "red", one to "green", etc.
  4. Put all the objects into the two arrays mentioned above.
    1. (car objects in cars array, motorcycle objects in motorcycles array)

  1. Then displays a series of things to the user with the following flow:

  1. First a menu for choosing which car to START:
    1. Lists the cars with numbers and asks which one to start.
      1. Use 1 to 3 as menu item numbers instead of 0 to 2.
    2. When item # chosen, then the start method for that object is called.
      1. The number they enter has to be adjusted for the correct array index obviously.

  1. Second is the menu for which motorcycle to START:
    1. Same as above except now for the motorcycle array.

  1. Third is the menu for which car to STOP:
    1. Same as the ones above except now the stop method is being called instead of start.

  1. Fourth is the menu for which motorcycle to STOP.
    1. Same as above, but now for motorcycle.

  1. Fifth, display all 6 vehicles status on whether they're running or not.

  1. Vehicle_Test
    1. Put the main method here.
      1. In the method, simply instantiate an instance of VehicleManager and call its run method.

  1. TURNING IN LAB:

  1. Turn your lab into Canvas where you got this lab doc.
  2. IMPORTANT: DO NOT ZIP your folders/files please.
  3. Turn in just the five raw java files (.java files) for this lab (dont turn in any .class files).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Technology

Answered: 1 week ago