Announcement

Collapse
No announcement yet.

Is anyone else doing JAVA Programming? I need help...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Is anyone else doing JAVA Programming? I need help...

    Ok so it is my first semester in Computer Science in College and we have this assignment which is to write a "Guessing Game". Basically the computer generates a random number from 1 to 100 and you have 10 tries to guess it right. Each time you get it wrong, it tells you whether you're over it or under it, giving you hints for you to guess. Then you have the option of typing in Y or N to play again. This is where I am having a problem. As odd as it is, yesterday it was working fine and nothing was modified I swear! It's as the language has been changed a little or something. This is the end part of it.. What is in red is where the problem is...

    See I want the user to be able to input Y or y to play again. However, as soon as I add the or sign || it doesn't work anymore. Although the answer is Y or y, it leads me to the part where it says that if the answer is not equal to Y or y or N or n, print Your answer is inappropriate... Now is I take out all the || and just leave 'Y' for instead, although the Y answer would have to be capital letter only, the program works... I hope this is clear enough... Anyway I am having the same problem with another program I'm writing... and i swear it worked the way it is written below yesterday...

    do
    {
    System.out.println("Do you want to play again Y/N?\n");
    String character = kb.next();
    answer = character.charAt(0);

    System.out.println();

    if(answer == 'N' || answer == 'n')
    {
    System.out.println("The program will now terminate...");
    System.exit(0);
    }

    if(answer != 'Y' || answer != 'y'|| answer != 'N' || answer != 'n')
    {
    System.out.println("Your answer is inappropriate...\n");
    }

    } while(answer != 'Y'|| answer != 'y' || answer != 'N' || answer != 'n');

    System.out.println("Guess the number...\n");

    } while(answer == 'Y' || answer == 'y');
    Last edited by Gyuri87; 10-26-2008, 03:01 AM.
    NEW MYRIDE THREAD


    PARTS 4 SALE

    #2
    Why not just re-copy the could for Y and then redo it for y, its the lazy mans fix but it will work for the time being, until you can ask your teacher for more help. Later this week I will run by my storage and find my old notes.

    "Real intelligence is like a river; the deeper it is, the less noise it makes.”

    Click Me

    Comment


      #3
      Originally posted by NorcoAccord View Post
      Why not just re-copy the could for Y and then redo it for y, its the lazy mans fix but it will work for the time being, until you can ask your teacher for more help. Later this week I will run by my storage and find my old notes.
      What do you mean re-copy the could for Y and then redo it for y?

      It's nothing super urgent... The teacher doesn't even check whether you did it or not. I mean you have to if you want to understand and pass the course and besides I pretty much like it. It just bothers me to encounter such a problem and not be able to proceed. The funny thing as I said is that yesterday it was working just fine the way it's written up there. I really don't get it.
      NEW MYRIDE THREAD


      PARTS 4 SALE

      Comment


        #4
        try doing

        %%If answer = N or n
        terminate

        else if answer = Y or y
        play again

        else

        answer inappropriate%%

        you'd still have to loop though

        ...adjust accordingly

        Comment


          #5
          Originally posted by LinX View Post
          try doing

          %%If answer = N or n
          terminate

          else if answer = Y or y
          play again

          else

          answer inappropriate%%

          you'd still have to loop though
          Is this even JAVA? I mean from what I see, it is exactly what I did... What's the remainder for?
          NEW MYRIDE THREAD


          PARTS 4 SALE

          Comment


            #6
            its pseudocode. JAVA has if, else if, and else statements that you could use. However, you still have to implement a loop to constantly check the user input.

            ...adjust accordingly

            Comment


              #7
              Originally posted by LinX View Post
              its pseudocode. JAVA has if, else if, and else statements that you could use. However, you still have to implement a loop to constantly check the user input.
              don't think he's into else statements yet. Sounds like he's at the beginning of the course.

              I'll try and find some of my old notes and try to help you. This was our first assignment back a few years ago.

              CrzyTuning now offering port services

              Comment


                #8
                Originally posted by d112crzy View Post
                don't think he's into else statements yet. Sounds like he's at the beginning of the course.

                I'll try and find some of my old notes and try to help you. This was our first assignment back a few years ago.
                I do know how else works but I don't need to use it in this particular situation...
                It is just like saying "if" this is it then to this but "else" if it isn't do that. I guess I'll wait and ask the teacher. The thing is that tomorrow I won't attend class because I have to go to court for a speeding ticket
                NEW MYRIDE THREAD


                PARTS 4 SALE

                Comment

                Working...
                X