I need some guidance with my program. My problem is I ask the car what it would like to do(start, drive, or stop).
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).
I got the program to where I can hit enter 1,2, or 3 for each
I also have to show the state of the car but at the time I am not worried about that. My initial issue right now is setting up rules for the three lines I provided. I am not looking for answers as I am trying to teach myself to develop but any help in what someone would recommend. I am adding my code as well as the initial instructions I received.
import java.util.Scanner; public class MyApp { public static void main(String [] args) { System.out.println("Start the app"); Car myCar = new Car(); Scanner keyboard = new Scanner(System.in); System.out.println("1: Start the car"); System.out.println("2: Drive the car"); System.out.println("3: Stop the car"); System.out.print("Enter a selection by typing 1, 2, or 3: "); int nova = keyboard.nextInt(); while ((nova != 1) && (nova != 2) && (nova != 3)) { System.out.println("Error!"); System.out.println("You must enter a valid selection!"); System.out.print("Enter a selection by typing 1, 2, or 3: "); nova = keyboard.nextInt(); } myCar.start(nova); } } //class car class Car { //public int watts = 100; private boolean isStarted = true; public void start(int nova) { //set rules for code } public void drive(int nova) { //set rules for code } public void stop(int nova) { //set rules for code } public String showState(int nova) { if(nova == 1) { System.out.println("You have started the car!"); } else if (nova == 2) { System.out.println("You are driving the car!"); } else if (nova == 3) { System.out.println("You have stopped the car!"); } return ; } }