"cannot be applied to ()" error?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cerise
    New Member
    • Dec 2007
    • 15

    #1

    "cannot be applied to ()" error?

    I'm trying to make an object to represent a single playing card. Like if it's an EIGHT of HEARTS, the object should be "8 H". Here is what I came up with, but I keep getting the error message,
    "DisplayDeck.ja va:12: switchRank(int) in DisplayCards cannot be applied to ()
    sRank = dispCards.switc hRank();" .
    The error points out the dot in "dispCards.switchRank()".

    Can someone help me out?

    Thank you.


    public class DisplayCards {
    String sRank = "";
    String sSuit = "";
    int rank = 1;
    int suit = 1;

    public String switchSuit(int suit) {
    switch(suit) {
    case 1:
    sSuit = "D";
    //break;
    case 2:
    sSuit = "H";
    //break;
    case 3:
    sSuit = "S";
    //break;
    case 4:
    sSuit = "C";
    //break;
    default:
    break;
    }
    return sSuit;
    }

    public String switchRank(int rank) {
    switch(rank) {
    case 1:
    sRank = "A";
    case 2:
    sRank = "2";
    break;
    case 3:
    sRank = "3";
    break;
    case 4:
    sRank = "4";
    break;
    case 5:
    sRank = "5";
    break;
    case 6:
    sRank = "6";
    break;
    case 7:
    sRank = "7";
    break;
    case 8:
    sRank = "8";
    break;
    case 9:
    sRank = "9";
    break;
    case 10:
    sRank = "10";
    break;
    case 11:
    sRank = "J";
    break;
    case 12:
    sRank = "Q";
    break;
    case 13:
    sRank = "K";
    break;
    default:
    break;
    }
    return sRank;
    }

    }



    this is the main class.

    public class DisplayDeck {
    public static void main(String[] args) {

    int rank = 0;
    String sRank="";
    DisplayCards dispCards = new DisplayCards ();


    rank = 2;
    sRank = dispCards.switc hRank();
    }
    }
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Your switchRank method needs a single parameter of type int; you defined it that
    way. You are trying to call it without using a parameter (see your main method).
    That's what your compiler is complaining about. You should pass a single int
    value to that method.

    kind regards,

    Jos

    Comment

    • cerise
      New Member
      • Dec 2007
      • 15

      #3
      Originally posted by JosAH
      Your switchRank method needs a single parameter of type int; you defined it that
      way. You are trying to call it without using a parameter (see your main method).
      That's what your compiler is complaining about. You should pass a single int
      value to that method.

      kind regards,

      Jos
      Thank you SO MUCH. It's compiling fine now.

      Comment

      Working...