Ok This is going to seem like a wierd question but I am working on a program and need some clarification. I tried to contacting my instructor but he has not gotten back to me yet. My issue is I am not sure how my instructor wants me to figure out how to start, drive , and stop the car in my program. I will give you the instructions below and my code(I know the start, drive, and stop functions are not correct but I was just playing with this program to get started with it)
Create a Java application consisting of two classes. Class one will be your application class. Class two will be a class called Car. Your application will create an instance of Car, called nova, and drive it.
Rules for the car:
You can’t drive a car if it is not started (send an error message to the console).
You can’t stop a car if it is not started (send an error message to the console).
You can’t start a car if it is already started (send an error message to the console).
Once you tell the car to drive, the only thing you can do is stop (Send a message to the console)
Once you call stop, the car will return to the initial state and the user must start the car before attempting to do any other functions. (Send a message to the console)
The purpose of the showState method is provide a way to inspect the state of the car. It should build a message, which can then be sent to the console.
Scenario 1:
1) Create instance of car
2) Start the car
3) Send status message to the console
4) Drive the car
5) Stop the car
6) Send status message to the console
Scenario 2:
1) Create instance of car
2) Send status message to the console
3) Drive the car
4) Stop the
5) Send status message to the console
Scenario 3:
1) Create instance of car
2) Send status message to the console
3) Start the car
4) Send status message to the console
5) Stop the car
6) Send status message to the console
7) Drive the car
8) Stop the car
here id my code
public class ProgrammingAssignment3 { public static void main(String [] args) { System.out.println("Start the app"); Car myCar = new Car(); //Function to start the car myCar.start(); //Function to drive the car myCar.drive(); //Function to stop the car myCar.stop(); //System.out.println(myLight.watts); //System.out.println(myLight.getIsOn()); //myLight.on(); //System.out.println(myLight.getIsOn()); System.out.println("End of app"); } } //class lightBulb class Car { //public int watts = 100; private boolean isStarted = true; public void start() { isStarted = (true); System.out.println("Start the car."); } public void drive() { while(isStarted = (false)) { System.out.println("Error!"); } System.out.println("Drive the car."); } public void stop() { while(isStarted = (false)) { System.out.println("Error!"); } System.out.println("Stop the car."); } //public String showState() //{ //return 0; //} }