Results 1 to 2 of 2
- 11-01-2012, 09:39 PM #1
Member
- Join Date
- Nov 2012
- Posts
- 1
- Rep Power
- 0
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();
}
}
}
}
}
- 11-02-2012, 09:52 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
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.Please do not ask for code as refusal often offends.
Similar Threads
-
checking entered text in a text box?
By nickburris in forum New To JavaReplies: 2Last Post: 06-24-2011, 02:09 AM -
Reading Text file to Data type Double
By orpheus2708 in forum New To JavaReplies: 17Last Post: 04-08-2011, 03:11 AM -
Error if someone enters the wrong data type
By lithium002 in forum New To JavaReplies: 43Last Post: 11-16-2009, 04:41 PM -
Hibernate mapping error Provided id of the wrong type with composite id
By zigzag in forum JDBCReplies: 1Last Post: 11-11-2008, 08:18 PM -
[SOLVED] How to check what type of value entered in text field
By Renegade85 in forum New To JavaReplies: 2Last Post: 04-28-2008, 10:26 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks