Hi I wonder if how can I put a validation on the while of if statements so the program will only execute if the user enters the commands "move" "line" "circle" with their parameters. For example if the user enters "move 200" the program will say Invalid because there's only one or NO parameter. Thanks!
import java.util.Scanner;
public class DrawingProgram1 {
public static void main(String[] args) {
GraphicsScreen g = new GraphicsScreen();
String store;
String command;
int move1;
int move2;
int line1;
int line2;
int circle;
while (true) {
Scanner scan = new Scanner(System.in);
System.out.println("Type 'help' for list of commands. Type 'end' to finish.");
System.out.println("Please enter a command:");
store = scan.nextLine();
String [] splitUpText = store.split(" ");
command = splitUpText[0];
if (command.equalsIgnoreCase("move")) {
move1 = Integer.parseInt(splitUpText[1]);
move2 = Integer.parseInt(splitUpText[2]);
g.moveTo(move1, move2);
}
else if (command.equalsIgnoreCase("line")) {
line1 = Integer.parseInt(splitUpText[1]);
line2 = Integer.parseInt(splitUpText[2]);
g.lineTo(line1, line2);
}
else if (command.equalsIgnoreCase("circle")) {
circle = Integer.parseInt(splitUpText[1]);
g.circle(circle);
}
else if (command.equalsIgnoreCase("help")) {
System.out.println("Enter a command for move.");
System.out.println("Enter a command for line.");
System.out.println("Enter a command for circle.");
}
else if (command.equalsIgnoreCase("end")) {
System.exit(0);
}
else {
System.out.println("Error");
}
}
}
}
splitUpText. If its not 3,continuethe while loop after showing the message.