Question: I just need the UML for this code /** * */ package topic1_3; /** * @author david * */ //Tire class //Tire class class Tire
I just need the UML for this code
/** * */ package topic1_3;
/** * @author david * */ //Tire class //Tire class class Tire { // variable for storing air pressure of tire int airPressure; // constructer of Tire public Tire() { airPressure = 32; }
// getter and setter method for air pressure void setAirPressure(int newPressure) { this.airPressure=newPressure; }
int getAirPressure() { return this.airPressure; } } //Class Car class Car { // variables for different properties of the car int engineCapacity,fuelTankCapacity,currentSpeed; String currentState;
// Array of tires objects Tire [] tires; // Constructer to set values to variables public Car(int engineCapacity,int fuelTankCapacity,Tire [] tires) { this.engineCapacity=engineCapacity; this.fuelTankCapacity=fuelTankCapacity; this.currentState="Stopped"; this.currentSpeed = 0; this.tires = tires; } // function to get current speed String getcurrentState() { return this.currentState; }
// function to start a car void startCar() { // flag to check if all tires have required pressure boolean isTiresGood=true;
// Loop to go through all tires and check their pressure for(int i=0;i<4;i++) { if(tires[i].getAirPressure() < 32) { isTiresGood=false; break; } }
// if tires are good then start the car print speeds if(isTiresGood) { // set state to started this.currentState="Started"; System.out.println("Car Started: "); // Loop will print speeds from 1-60 for(int i=0;i<=60;i=i+5) { System.out.println("Car speed is "+ i); this.currentSpeed=i; } } // if tires are not good print message else { System.out.println("Tires Pressure is not enough for starting the car"); } }
// function to stop the car void stopCar() { // if state is started then stop the car if(currentState.equals("Started")) { this.currentState = "Stopped"; this.currentSpeed = 0; } // if car is already stopped then print message else { System.out.println(" Car is already stopped!"); } }
// method to restart car by calling start car function void restartCar() { System.out.println("Starting the car again "); this.startCar(); }
// to string method to return all details as a string public String toString() { String output=" Details of the car: "; output += " Current speed: "+this.currentSpeed; output += " Current state: "+this.currentState;
return output; } }
//Main driver class public class Driving { public static void main(String[] args) { // creating array of tires Tire [] tires = new Tire[4]; // Assigning objects to array tires [0] = new Tire(); tires [1] = new Tire(); tires [2] = new Tire(); tires [3] = new Tire(); // creating a object of car and calling start and stop function Car myCar = new Car(1000,15,tires);
myCar.startCar();
myCar.stopCar();
// printing details of a car System.out.println(myCar.toString());
} }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
