So far, it's all working great, but all I need left is to get the method WORD1() to go to WORD2() when the person types in the correct letters. The first word is "Java". How would I make it so that when they type in "Java", it will go to WORD2()?

public static void main(String[] args) {
    
    STAND();
    WORD1();
    WORD2();
    
  }

  public static void WORD1() { //Java
    char[] JAVA = {'j','a','v'};
    char key = ' ';
    String done;
    
    c.setFont(new Font("arial", Font.PLAIN, 50));
    c.setColor(Color.BLACK);
    c.drawString("_", 251, 472);
    c.drawString("_", 287, 472);
    c.drawString("_", 322, 472);
    c.drawString("_", 357, 472);
    
    while(key != 'J' || key != 'A' || key != 'V' || key != 'j' || key != 'a' || key != 'v')
    {
      key = c.getChar();
      
      if (key == 'J' || key == 'j')
      {
        c.setFont(new Font("arial", Font.BOLD, 50));
        c.setColor(Color.BLACK);
        c.drawString("J", 250, 470);
      }
      else if (key == 'A' || key == 'a')
      {
        c.setFont(new Font("arial", Font.BOLD, 50));
        c.setColor(Color.BLACK);
        c.drawString("A", 285, 470);
        c.drawString("A", 355, 470);
      }
      else if (key == 'V' || key == 'v')
      {
        c.setFont(new Font("arial", Font.BOLD, 50));
        c.setColor(Color.BLACK);
        c.drawString("V", 320, 470);
      }
      else if(JAVA[0] == 'j' && JAVA[1] == 'a' && JAVA[2] == 'v')
      {
        c.clear();
        counter = 0;
        STAND();
        WORD2();
      }
      else if(key != 'J' || key != 'A' || key != 'V' || key != 'j' || key != 'a' || key != 'v')
      {
        COUNTER();
        
        if(counter == 11)
        {
          c.clear();
          c.setFont(new Font("arial", Font.PLAIN, 25));
          c.setColor(Color.BLACK);
          c.drawString("You          him! Try the next word!", 125, 250);
          c.setColor(Color.RED);
          c.drawString("killed", 174, 250);
          
          c.setFont(new Font("arial", Font.PLAIN, 15));
          c.setColor(Color.BLACK);
          c.drawString("The next word will automatically start in 5 seconds.", 150, 275);
          
          WAIT();
          c.clear();
          counter = 0;
          STAND();
          WORD2();
        }
      }
    }
  }

  public static void WORD2() {
    //code here
  }

Arg, I don't have much time to finish this project. :/ I've been trying but can't seem to get it working.

The code you've posted looks like a collection of may different attempts to solve the problem and has gotten to be a mess.
Perhaps you should trash it and start over with a new design. Leave out the drawing and GUI stuff and just work on the logic of how to read in the letters and test when you have the correct letters in the correct sequence.

Start with creating new logic and then code it.

I would if I had the time to. This took long enough to make since I am a beginner.

How about starting with a simple version of the program where each WORDi method only needs to read in and accept/validate one or two letters instead of 4. When you get the logic worked out, then you could move to the 4 letters you are trying to process now.

I only need 5 words for this program. I just seriously need help doing the returning. Could you maybe show me how you'd do it?

My suggestion is to start with a simple program, figure out the logic for one letter for each method and when that works, move on to two letters for each method.
When you get that to work, you should have the idea on how to write the logic for more letters.

Good luck.

...how many times should I repeat myself? I'd like to stick with what I have but I'd like to learn how to use the returning.

No one is going to do your homework for you. Also you should keep in mind many schools automatically search forums and compare them to submitted homeworks. If you plan on taking code from forums you will most likely get caught and in trouble.

I suggest learning how to program and trying to do it yourself first. When you a problem then ask for a few pointers. No one is going to do all of your work for you.

I'm not asking for someone to do the homework for me. I'm just asking for an example of how I could use the returning in this situation so that I can implement it into it.

Here's a simple example:

private void aMethod(int x) {
  if (x < 10)  // Test if the value in range
     return;   // exit the method if too small
   // do other stuff here
} // end aMethod()
commented: ty +1

So, in this case should I be using ints or Strings?

Use ints for numberic data and Strings for string data.

I'm not sure what the "case" is you are talking about.

I'm still lost as to how I could make this work using returning. Sorry. :/

Please describe in more detail what you want your program to do.
You need to have a design for the program before you write it.
What you have posted now is a mixed up mess.

My suggestion is to start with a simple program, figure out the logic for one letter for each method and when that works, move on to two letters for each method.
When you get that to work, you should have the idea on how to write the logic for more letters.

Alright, sorry if I wasn't clear in the OP. The current problem is: once the person fills out the required letters for the first word ("Java"), it doesn't automatically go to the second word which is method WORD2().

In other words:

- I type "J", "A", and "V" into the keyboard, completing the word.
- When I have "JAVA" filled out, it doesn't automatically go to WORD2() as it should.

WORD1 should return to the calling method when it has received the 4 letters.
The calling method can then call the WORD2 method.
also the WORD1 method could return an error code if there was a problem to tell the calling method about it.

I would also think really carefully about what you think this line is doing for you

else if(JAVA[0] == 'j' && JAVA[1] == 'a' && JAVA[2] == 'v')

WORD1 should return to the calling method when it has received the 4 letters.
The calling method can then call the WORD2 method.
also the WORD1 method could return an error code if there was a problem to tell the calling method about it.

There's my problem. I'm not sure how to check if it has the 4 letters, and overall, returning.

My suggestion is to start with a simple program, figure out the logic for one letter for each method and when that works, move on to two letters for each method.
When you get that to work, you should have the idea on how to write the logic for more letters.

I don't have that much time on my hands...

If you don't have time to figure out how to write simple code and learn the techniques needed to do that, I can only wish you good luck.

> I don't have that much time on my hands...

That's unfortunate, because you still have a lot of work left on this.

Can you answer the question I posed above?

Can you explain how this will ever allow you to enter any more than one letter out of the three you're expecting?

while(key != 'J' || key != 'A' || key != 'V' || key != 'j' || key != 'a' || key != 'v')
{
key = c.getChar();

This code is just not workable and you really need to take NormR1's advice and step back to a simpler case and work from there.

I would also think really carefully about what you think this line is doing for you

else if(JAVA[0] == 'j' && JAVA[1] == 'a' && JAVA[2] == 'v')

I was trying out what Norm suggested but obviously I don't know how to use it properly.

> I don't have that much time on my hands...

That's unfortunate, because you still have a lot of work left on this.

Can you answer the question I posed above?

Can you explain how this will ever allow you to enter any more than one letter out of the three you're expecting?

while(key != 'J' || key != 'A' || key != 'V' || key != 'j' || key != 'a' || key != 'v')
{
key = c.getChar();

This code is just not workable and you really need to take NormR1's advice and step back to a simpler case and work from there.

I've been trying to fiddle with that, but can't get it to work.

All I need for now (if you could please help me) is this:

"The current problem is: once the person fills out the required letters for the first word ("Java"), it doesn't automatically go to the second word which is method WORD2().

In other words:

- I type "J", "A", and "V" into the keyboard, completing the word.
- When I have "JAVA" filled out, it doesn't automatically go to WORD2() as it should. "

When WORD1 determines that the required letters have been entered, it should return.
Then the calling method can call WORD2

That's where I'm stuck as I've repeated so many times. I don't know how to make it check for those letters, and return it. Anyway you can show me using my code? :(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.