You are on page 1of 3

Body Class

Engine Class

public class Body { //Beginning of Body class //Declare Body class Attributes private String type; //Class's Methods and behaviour public void setBody() { //Assign the type value of the Body System.out.println("Enter the Body's Type"); type = in.readLine(); } public void describe() { // Display the Car's Body Type System.out.println("Car Type is: " + type); } } //End of class Body

public class Engine {//Beginning of Engine class //Declare Engine class Attributes private int power; //Class's Methods and behaviour public void setEngine() { // Assign the Power value of the engine power = Integer.parseInt(in.readLine()); } public void describe() { // Display the Power value of the engine System.out.println("Engine power is = " + String.valueOf(power)); } } //End of class Engine
System.out.println("Enter the engine's power");

Car Class

public class Car ' Beginning of Car class { private int passengers, speed; //Declare Car class Attributes private Engine engine; //Declare new instant of class Engine private Body body; //Declare new instant of class Body //Class Methods and behaviour public void setCar() { engine = new Engine(); engine.setEngine();//Instantiate Engine object body = new Body(); body.setBody();//Instantiate Body object } public void describe() { engine.describe(); body.describe(); } public void status() { System.out.println("Enter the No. of Passengers"); passengers = Integer.parseInt(in.readLine()); if (passengers == 0) { System.out.println("Car is Stopping"); } else { System.out.println("Enter the Car Speed"); speed = Integer.parseInt(in.readLine()); if (speed > 50) {System.out.println("Over Speed"); } else {System.out.println("Within Normal Speed"); } }

Program Start Here


'the main program start here public class Module { public static void main(.) { // create new instance Car car1 = new Car(); car1.setCar(); car1.describe(); car1.status(); // create new instance Car car2 = new Car(); car2.setCar(); car2.describe(); car2.status(); } }

Does the user assign a value to variable "Body"? (Yes/No/Do not Know) Is the variable "Passengers" initialized to zero? (Yes/No/Do not Know) Does the user assign a value to variable "Speed"? (Yes/No/Do not Know)
In "Car_Status" method in class "Car", does "Speed" value assigned in the case of "Passengers" =zero? (Yes/No/Do not

Know)

Is the value of variable "Speed" assigned before the value of variable "Passengers"? (Yes/No/Do not Know) In "Set_Car" method in class "Car", does the program instantiate engine before body? (Yes/No/Do not Know)

Does the value of "Passengers" affect the value of "Speed"? (Yes/No/Do not Know) Does the value of "Type" in class "Body" affect the value of "Power" in class "Engine"? (Yes/No/Do not Know) Does the program allow you to create new car with a certain type and power? (Yes/No/Do not Know) Does the program allow you to change the car specifications (Type / Power)? (Yes/No/Do not Know)

Does the program compare number of passengers in two cars? (Yes/No/Do not Know) Which of these classes are defined in the program Yes (Body) No Do not know (Car) Yes No Do not know Yes Yes (Wheels) No Do not know (Engine) No Do not know Yes Yes (Lorry) No Do not know (Passengers) No Do not know

When the Car is Stopping statement is reached, is the value of "Passengers" > zero?

( Yes/No/Do not Know)

When the Over Speed statement is reached, is the value of "Speed" = 50? (Yes/No/Do not Know) Now Write a short Summary of what this program does

You might also like