import java.util.Scanner;
/**
* This provides a simple to complex when complete example of how to read input from the keyboard until a
* certain piece of text has been input.
*
* @author n.hussain
*
*/
public class InputExample {
private static Scanner input;
public final static void main(String [] args ) {
input = new Scanner(System.in);
String next; // stores the next line input
System.out.println("Let's draw something on the screen!");
GraphicsScreen graphics = new GraphicsScreen();
//graphics.moveTo(100, 100);// move to 100 pixels right, and 100 down.
//graphics.lineTo(250, 200);// draw a line to the centre of the screen
//graphics.circle(50);// draw a circle at the end of the line
//graphics.lineTo(400, 100);// draw a second line
//graphics.lineTo(100, 100);// draw back to the starting point
do {
System.out.print("Enter a command (\"stop\") to finish : ");
next = input.nextLine();
String [] splitupText = next.split(" ");
String command = splitupText[0];
if(command.equals("circle")){
String val1 = splitupText[1];
int circle = Integer.parseInt(val1);
graphics.circle(circle);
}
if(command.equals("moveTo")){
String val2 = splitupText[1];
int v2 = Integer.parseInt(val2);
String val3 = splitupText[2];
int v3 = Integer.parseInt(val3);
graphics.moveTo(v2, v3);
}
if(command.equals("lineTo")){
String val2 = splitupText[1];
int x = Integer.parseInt(val2);
String val3 = splitupText[2];
int y = Integer.parseInt(val3);
graphics.lineTo(x,y);
}
if (command.equals("lineTo")){
String val2 = splitupText[1];
int v2 = Integer.parseInt(val2);
String val3 = splitupText[2];
int v3 = Integer.parseInt(val3);
graphics.lineTo(v2,v3);
}
}
while ( next.equalsIgnoreCase("stop") == false );
System.out.println("You have decided to stop entering commands. Program terminated!");
}
}
I am fairly new to programming and need help to include some validation in my code, i have done research but i need a starting point.

New Topic/Question
Reply



MultiQuote







|