want error messages for wrong data type in like text and when nothing is entered
import java.util.Scanner; // used to read the keyboard
public class programme { // the public classs
public static void main(String[] args) { //the main method
programme obj = new programme();
obj.go();
}
public void go() //
{
GraphicsScreen g = new GraphicsScreen();
while(true)
{
System.out.println("Please enter your commands here Type 'help' for a list of commands and 'end' to finish: "); // used to output command that user can read
Scanner scan = new Scanner(System.in); // scans the keyboard
String cmd = scan.nextLine(); // scans the next line
String [] userParam = cmd.split(" "); // spliter
int num1 = 0; // varibles for the sizes the user wants they circle drawn
int num2 = 0;
{
if (userParam[0].equals("move"))
{
num1 = Integer.parseInt(userParam[1]); //attempt to convert the String into an Integer type value
num2 = Integer.parseInt(userParam[2]);//attempt to convert the String into an Integer type value
if (userParam[1] .equals(""))
System.err.println("Please enter move followed by 2 coordinates ");
System.out.println("Your circle will move");
g.moveTo(num1,num2); // g.move is the code to move the circle to the postion the user wants the circle
}
else if (userParam[0].equals("circle"))
{
System.out.println("circle will be drawn ");
num1 = Integer.parseInt(userParam[1]);
g.circle(num1);
}
else if (userParam[0].equals(""))
System.err.println("Please enter circle followed by 1 coordinate ");
else if (userParam[0].equals("line"))
{
System.out.println("the circle will have a line running through it");
num1 = Integer.parseInt(userParam[1]); // parse Int integer, given a string representation of decimal, binary, octal, or hexadecimal
num2 = Integer.parseInt(userParam[2]);
g.lineTo(num1, num2); //draws line to users required x and y coordinates and the varibles represent the x and y coordinates entered by the user
}
else if (userParam[0].equals("help"))
{
System.out.println("Enter move in lower case and the x and y coordinates you want to move the circle");
System.out.println("Enter circle lower case and coordinates you want for the circle");
System.out.println("Enter line lower case and the x and y coordinates you want for the line");
System.out.println("Enter clear lower case and this will clear the circle that has been drawn");
System.out.println("Enter close lower case and the program will close");
}
else if (userParam[0].equals("clear"))
{
g.clear(); // this clears everything off the graphic screen
}
else if (userParam[0].equals("close")) // this ends the graphic screen
{
System.out.println("Your program is now closed if you want to use it again please run the program again");
g.close();
}
}
}
}
}
Re: want error messages for wrong data type in like text and when nothing is entered
Please use [code] tags [/code] when posting code.
Many of us will not read unformatted code.
You might also need to expand on your problem, as I'm not entirely sure what you need.