简体   繁体   中英

Method not being recognized even when declared

So, I am creating a project of a basic "arcade". I have cards which are passed into games(methods). I created a method in my Card class to have the ability to chose which cards to use for the games.

public Card choosecard(Card firstCard, Card secondCard) {

   Scanner input = new Scanner(System.in);

   Card chosen = new Card();
   boolean check = false;

   while(check == false) {

   System.out.println("What card would you like to use?\n  1. " + firstCard.name + "\n  2. " + secondCard.name);
   int answer = Integer.parseInt(input.nextLine());

   if(answer == 1) {
       chosen = firstCard;
       check = true;
   }
   else if(answer == 2) {
       chosen = secondCard;
       check = true;
   }
   else {

   }

   } //while

   return chosen;

After creating this method I tried calling it in this context:

public static void terminal(Card card1, Card card2) {

    boolean loop = true;
    while(loop == true) {

    System.out.println("What would you like to do?\n1. Guess Game\n2. Transfer\n3. Prizes\n4. Cancel");
    Scanner take = new Scanner(System.in);
    int answer = Integer.parseInt(take.nextLine());

    switch(answer) {

        case 1: 
            Game.GuessGame(Card.chooseCard(card1, card2));

    }

    } 

I thought that it may be because im trying to call a method in the parameters of another method. So I tried calling it from other classes but it still gives the cannot find symbol error.

Thank you.

public Card choosecard(Card firstCard, Card secondCard)

Its not a static method.

Game.GuessGame(Card.chooseCard(card1, card2));

But Card.chooseCard(card1, card2) means you are calling it statically.

Consider making it static or calling via object.

Card.chooseCard(card1, card2) means calling a static method. You may want to declare chooseCard as

public static Card choosecard(Card firstCard, Card secondCard)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM