Results 1 to 2 of 2
  1. #1
    joec0nyers is offline Member
    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    Default 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();
    }
    }
    }

    }
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default 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.

    ** This space for rent **

Similar Threads

  1. checking entered text in a text box?
    By nickburris in forum New To Java
    Replies: 2
    Last Post: 06-24-2011, 02:09 AM
  2. Reading Text file to Data type Double
    By orpheus2708 in forum New To Java
    Replies: 17
    Last Post: 04-08-2011, 03:11 AM
  3. Error if someone enters the wrong data type
    By lithium002 in forum New To Java
    Replies: 43
    Last Post: 11-16-2009, 04:41 PM
  4. Replies: 1
    Last Post: 11-11-2008, 08:18 PM
  5. Replies: 2
    Last Post: 04-28-2008, 10:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •