String to int??? I've seen this done like this before. Mine just doesn't want to agre

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Hearton
    New Member
    • Dec 2014
    • 1

    String to int??? I've seen this done like this before. Mine just doesn't want to agre

    Code:
    import java.util.Scanner;
    public class Card
    {
    
       private int num;   // 2...10, 11=J, 12=Q, 13=K, 14=A
       private int suit;  // 0=club, 1=diamond, 2=heart, 3=spade
    
       //**********************************************************
    
       public Card(int num, int suit)
       {
          this.num = num;
          this.suit = suit;
       } // end constructor
    
       //**********************************************************
    
       public int getNum()
       {
           
    	    if (num == 2)
            return "2";
           if (num == 3)
            return "3";
           if (num == 4)
            return "4";
           if (num == 5)
            return "5";
           if (num == 6)
            return "6";
           if (num == 7)
            return "7";
           if (num == 8)
            return "8";
           if (num == 9)
            return "9";
           if (num == 10)
            return "10";
           if (num == 11)
            return "Jack";
           if (num == 12)
            return "Queen";
           if (num == 13)
            return "King";
           if (num == 14)
            return "Ace";
       } // end constructor
    
       //**********************************************************
    
       public int getSuit()
       {
        if (suit == 0)
         return "Clubs";
        
        if (suit == 1)
         return "Diamonds";
        
        if (suit == 2)
         return "Hearts";
         
        if (suit == 3)
         return "Spades";
          
       } // end constructor
    
       //**********************************************************
    
       public void display()
       {
          System.out.print(num, "of", suit);
          
       } // end display
    } // end Card class
    Card.java:27: error: incompatible types: String cannot be converted to int

    I don't want to convert a string to an int. I just want to return a string from the specified int. Any help??
    Last edited by Rabbit; Dec 9 '14, 05:09 AM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Please use code tags when posting code or formatted data.

    The problem is that on line 18, you tell the program that you are returning an into.

    Comment

    Working...