1 2 Previous Next 26 Replies Latest reply: May 22, 2008 8:47 AM by 807601 RSS

    String valid check

    807601
      I need to write a public instance method called isValidMove() which takes a String
      argument and which returns true if the argument represents a valid type of dance
      ("flip" or "slide"), false otherwise.

      This is what I've got so far, but it doesn't seem to be right.
      public void isValidMove()
            {
               String Move;
               Move = OUDialog.request("Please enter a move");
               if (Move == "flip" or Move == "side")
               {
                   OUDialog.alert("true");
                  }
                  else
                  {
                      OUDialogue.alert("false");
                  }
              }
      I get an error saying "( is expected"

      Anyone help?

      Edited by: ViperB on May 22, 2008 6:26 AM
        • 1. Re: String valid check
          807601
          Try reading the Java tutorials. What is UODialog?
          public void isValidMove() {  //Proper Java syntax
                  String Move;
                  Move = OUDialog.request("Please enter a move");
                  if (Move.equals()"flip") || Move.equals("side") {  //== is used for comparison, but use equals() for Strings, and or isn't a Java keyword; || represents a conditional OR in Java
                      OUDialog.alert("true");
                     } else {
                         OUDialogue.alert("false");
                     }
             }
          Edited by: codingMonkey on May 22, 2008 6:29 AM
          • 2. Re: String valid check
            807601
            It's part of the library I'm using

            Let me test the code you've edited.

            Which tutorials should I use for this kind of stuff?

            Edited by: ViperB on May 22, 2008 6:39 AM
            • 3. Re: String valid check
              807601
              This is what I've got now.
              public void isValidMove() 
                    {  
                      String Move;
                      Move = OUDialog.request("Please enter a move");
                      if (Move.equals()"flip" || Move.equals()"side") 
                      {
                          OUDialog.alert("true");
                         } 
                         else 
                         { 
                           OUDialog.alert("false");
                         }
              but I'm still receiving the same error.
              • 4. Re: String valid check
                807601
                By the way,
                Move.equals()"flip")
                has a typo; it should be
                Move.equals("flip")
                Start here .
                • 5. Re: String valid check
                  807601
                  On which line does the error occur?
                  • 6. Re: String valid check
                    800298
                    There are several problems here.
                    1. You are missing the closing bracket for this method.
                    2. The strings you want to compare should be inside the brackets of the equals() method.
                    3. According to Java conventions, variables should start with a lower case letter, so move instead of Move.
                    public void isValidMove()
                    {  
                            String move;
                            move = OUDialog.request("Please enter a move");
                            if (move.equals("flip") || move.equals("side")) 
                            {
                                OUDialog.alert("true");
                            } 
                            else 
                            { 
                                 OUDialog.alert("false");
                            }
                    }
                    • 7. Re: String valid check
                      807601
                      Edward_Kimber wrote:
                      There are several problems here.
                      1. You are missing the closing bracket for this method.
                      Where? Sorry, I didn't see that in reply 3.
                      2. The strings you want to compare should be inside the brackets of the equals() method.
                      Already pointed that out.
                      3. According to Java conventions, variables should start with a lower case letter, so move instead of Move.
                      True, but that wouldn't cause an error.

                      Edited by: codingMonkey on May 22, 2008 6:58 AM
                      • 8. Re: String valid check
                        807601
                        Thanks a lot Edward, works fine now.

                        However, I was working on another section, and getting a different error, again bracket related.

                        I'm writing a method called promptForNumOfMoves() which takes no
                        arguments and returns an integer between 1 and 5 (inclusive).

                        I've used a dialogue box to prompt the user for the number of dance moves
                        required, which is then validated.
                        public void promptForNumOfMoves()
                                {
                                    String stringInput;
                                    int intInput;
                                    stringInput = OUDialog.request("Please enter a number");
                                    intInput = Integer.parseInt(stringInput);
                                    if ((intInput <= 5) && (intInput => 1))  // says illegal start of expression
                                    {
                                        OUDialog.alert("Your number of moves are" + Input);
                                    }
                                    else
                                    {
                                        stringInput = OUDialog.request("Please enter a valid number");
                                    }
                                }
                        I'm getting an error in the place I've pointed out.

                        Edited by: ViperB on May 22, 2008 7:00 AM
                        • 9. Re: String valid check
                          807601
                          Change
                          =>
                          to
                          >=
                          • 10. Re: String valid check
                            807601
                            Still says the same thing.
                            • 11. Re: String valid check
                              807601
                              Does the comment in your code have 2 slashes? //? Your original post only had one.
                              • 12. Re: String valid check
                                807601
                                2 slashes, I edited the original post. :)
                                • 13. Re: String valid check
                                  807601
                                  I know. But did you edit your code?
                                  • 14. Re: String valid check
                                    807601
                                    Yes.

                                    And I'm still getting the 'illegal start of expression' error.
                                    1 2 Previous Next