Question: public class Car { / / Static constant integer: ( MAX _ SPEED ) set it to 2 0 0 ( Maximum speed in km
public class Car Static constant integer: MAXSPEED set it to Maximum speed in kmh Write your code here Instance variables: brand: string, model: String, current Speed : int & fuelType : constant String Write your code here Constructor public CarString fuelType this.brand "Unknown"; this.model "Unknown"; this.fuelType fuelType; this is a "MUST implemented" step, why? this.currentSpeed ; Start with zero speed Method chaining for setting brand public Car setBrandString brand note how the return data type is Car set the brand data members to the parameter return the instance Method chaining for setting model public Car setModelString model set the model data members to the parameter return the instance Method to accelerate the car public Car accelerateint speedIncrement if Write your code here check if the current speed speed increment is less or equal the max speed update the current Speed by adding the speedIncrement to it else System.out.printlnCannot exceed maximum speed of MAXSPEED kmh; return the instance Method to display car information public void displayInfo System.out.printlnCar: brand model; System.out.printlnCurrent Speed: currentSpeed kmh; System.out.printlnMaximum Speed: MAXSPEED kmh; System.out.printlnFuel Type: fuelType; Overloaded method to display car information with additional details public void displayInfoboolean showDetails displayInfo; Reuse existing displayInfo method if showDetails System.out.printlnAdditional Details: coming soon"; Placeholder for details public static void mainString args Create instances of Car and demonstrate method chaining Car car new CarToyota "Camry", "Gasoline"setBrandHondasetModelAccordaccelerate; Display car information using method chaining cardisplayInfo; Display car information with additional details Car car new CarBMWX "Diesel"; cardisplayInfotrue;
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
