Question: fix the errors in the code, the 2 errors in the code are ain.java: 1 0 : error: class Engine is public, should be declared
fix the errors in the code, the errors in the code are ain.java:: error: class Engine is public, should be declared in a file named Engine.java public class Engine Main.java:: error: class Car is public, should be declared in a file named Car.java public class Car errors.
Engine class
public class Engine
private int engineNum;
private int ccRating;
Default constructor
public Engine
this.engineNum ;
this.ccRating ;
Parameterized constructor
public Engineint engineNum, int ccRating
this.engineNum engineNum;
this.ccRating ccRating;
Method to set engine details
public void setEngineint engineNum, int ccRating
this.engineNum engineNum;
this.ccRating ccRating;
Getter for engineNum
public int getEngineNum
return this.engineNum;
Getter for ccRating
public int getCcRating
return this.ccRating;
Display engine details
public void showEngine
System.out.printlnEngine Number: this.engineNum CC Rating: this.ccRating;
Car class
public class Car
private int numDoors;
private String make;
private String model;
private Engine engine; Composition relationship with Engine
Default constructor
public Car
this.numDoors ;
this.make ;
this.model ;
this.engine new Engine; Create a default engine
Parameterized constructor
public Carint numDoors, String make, String model, int engineNum, int ccRating
this.numDoors numDoors;
this.make make;
this.model model;
this.engine new EngineengineNum ccRating;
Copy constructor
public CarCar otherCar
this.numDoors otherCar.numDoors;
this.make otherCar.make;
this.model otherCar.model;
this.engine new EngineotherCarengine.getEngineNum otherCar.engine.getCcRating;
Set car information
public void setInfoint numDoors, String make, String model
this.numDoors numDoors;
this.make make;
this.model model;
Update car details
public void updateCarint numDoors, String make, String model
this.numDoors numDoors;
this.make make;
this.model model;
Update engine details
public void updateEngineint engineNum, int ccRating
this.engine.setEngineengineNum ccRating;
Display car details
public void displayCar
System.out.printlnCar Details:";
System.out.printlnDoors: this.numDoors;
System.out.printlnMake: this.make;
System.out.printlnModel: this.model;
this.engine.showEngine; Display engine details
Calculate car cost
public int calCost
return this.engine.getCcRating this.numDoors ;
Accessor to get the cost of the car
public int getCost
return calCost;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
