Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using the solution created in question 2 you are going to create a nested static class that will hold the details of the engine used

Using the solution created in question 2 you are going to create a nested static class that will hold the details of the engine used within the vehicle.

a. Open the vehicle class.

b. Under the constructor method create a public static class named Engine.

c. Create two private static final variables named MAKE and CAPACITY. Make will hold text while capacity will store whole numbers.

d. The values that you should assign to the variables are Predicter and 1600

e. Do not create a constructor for this class.

f. Create two public static getters for both of the variables created.

g. Update the toString method in the Vehicle class to display the engine make and model. Remember the Engine is a static class.

The output of the program for each vehicle should now look like this:

The vehicle is manufactured by: Seer

The model type is Edict

The chassis number is ch2

The engine make is Predicter

The engine capacity is 1600cc

Solution for question 2:

class Vehicle{
 public static String MAKE ="Augur";
 public static int numVehicles = 0;
 private String chassisNo, model;
 public Vehicle(){};
 public Vehicle(String model){
 this.model = model;
 numVehicles = numVehicles+1;
 chassisNo = "Ch"+Integer.toString(numVehicles);
 System.out.println("Vehicle manufactured");
 }
 // added a method setMake() and set the static variable name to the name passed in this method
 public void setMake(String make){
 MAKE=make;
 }
 public void setChassisNo(String cNo){
 this.chassisNo = cNo;
 }
 
 public void setModel(String model){
 this.model = model;
 }
 public String getChassisNo(){
 return chassisNo;
 }
 public String getModel(){
 return model;
 }
 public void ToString(){
 System.out.println("The vehicle is Manufactured by : "+ MAKE);
 System.out.println("The model type is : "+this.getModel());
 System.out.println("Number of vehicles manufactured: "+this.getChassisNo());
 System.out.println("Number of vehicles manufactured: "+numVehicles);
 }
 
}

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

Recommended Textbook for

Advanced Database Systems For Integration Of Media And User Environments 98

Authors: Yahiko Kambayashi, Akifumi Makinouchi, Shunsuke Uemura, Katsumi Tanaka, Yoshifumi Masunaga

1st Edition

9810234368, 978-9810234362

More Books

Students also viewed these Databases questions