Results 1 to 4 of 4
  1. #1
    Azndaddy is offline Member
    Join Date
    Mar 2008
    Posts
    24
    Rep Power
    0

    Default [SOLVED] Check command

    Hi, how code is needed to check an input of command so that, when the command is entered wrong it would return null;

    example: on this class
    PHP Code:
    public class Quit extends Commands
    {
        public Quit(Editor editor)
        {
            super("quit", editor);    
        }
        
        public void execute()
        {
            System.out.println("Bye!");
            System.exit(0);
        }
    }
    Help would be great

    Thanks

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    If your command is a string, I think it is "Bye!", simply use a boolean variable, with comparing Strings. It the variable is true, do the process you want. If it is false do nothing.

  3. #3
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    9

    Default

    Azndaddy, what you're referring to is basic programming logic, fundamentally in the if/then area of logic. This will be a common task throughout your programming career and in this case, because the code you provided is a little obscure, is a task only you will be able to complete.

    Post more general code and we can assist. But basically, it goes something like this:
    Java Code:
    ...
    if (command != desired) {
      // do something to imply wrong command
    } else {
      // do the thing you were meaning to do
    }
    ...
    Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
    Want to voice your opinion on your IDE/Editor of choice? Vote now!
    Got a little Capt'n in you? (drink responsibly)

  4. #4
    Azndaddy is offline Member
    Join Date
    Mar 2008
    Posts
    24
    Rep Power
    0

    Default

    yeah i know its the basic, but it been too long since i touched java programming. i'll see what i can do.

    thanks for the help

Similar Threads

  1. CRC check program 1 error
    By javakid9000 in forum New To Java
    Replies: 1
    Last Post: 03-19-2008, 06:04 AM
  2. Can someone check my code
    By joz_12345 in forum Java 2D
    Replies: 7
    Last Post: 02-18-2008, 03:58 AM
  3. spell check
    By kazitula in forum Java Applets
    Replies: 2
    Last Post: 12-20-2007, 12:37 PM
  4. check command method please
    By dirtycash in forum New To Java
    Replies: 1
    Last Post: 12-06-2007, 10:35 PM
  5. Unable to execute command line command in java
    By LordSM in forum New To Java
    Replies: 1
    Last Post: 08-08-2007, 01:23 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
  •