Results 1 to 5 of 5
  1. #1
    cloutier172 is offline Member
    Join Date
    Oct 2011
    Posts
    5
    Rep Power
    0

    Default tryting to use switches, classes, and cant get it to work

    im trying to get it to print out what card im looking for so 3 , 2 would be "The Three of Diamonds" but it is not even printing out the "test print" not sure where to go next any ideas??

    Java Code:
    public class Card {
        
        public static void main(String[] args) {        
            System.out.println("test print");
            Suite suite = new Suite();
            Rank rank = new Rank();
            System.out.println(rank.getRank(3)+ suite.getSuite(2));
       
        }
    
      
    }
    class Rank{
        String getRank(int getRank){
            String newRank;
            switch(getRank){
                case 1: newRank = "The Ace"; break;
                case 2: newRank = "The Two"; break;
                case 3: newRank = "The Three"; break;
                case 4: newRank = "The Four"; break;
                case 5: newRank = "The Five"; break;
                case 6: newRank = "The Six"; break;
                case 7: newRank = "The Seven"; break;
                case 8: newRank = "The Eight"; break;
                case 9: newRank = "The Nine"; break;
                case 10: newRank = "The Ten"; break;
                case 11: newRank = "The Jack"; break;
                case 12: newRank = "TheQueen"; break;
                case 13: newRank = "The King"; break;
                default : newRank = "out of range"; break;
            }
            return newRank; 
        }
        
    }
    class Suite{
        
        String getSuite(int getSuite){
            String newSuite;
            switch(getSuite){
                case 1: newSuite = " of Clubs"; break;
                case 2: newSuite = " of Diamonds"; break;
                case 3: newSuite = " of Hearts"; break;
                case 4: newSuite = " of Spades"; break;
                default : newSuite = "Suite out of range"; break;
            }
            return newSuite;
        }
        
    }

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: tryting to use switches, classes, and cant get it to work

    The "test print" line is the first line. If it is not being executed then you are not running the correct program. Provide full details of how you are compiling and running your code. As well as any error messages.

  3. #3
    cloutier172 is offline Member
    Join Date
    Oct 2011
    Posts
    5
    Rep Power
    0

    Default Re: tryting to use switches, classes, and cant get it to work

    im using netbeans to write the code and run it. im not getting any errors but it is also not printing anything. ya i cant figure out why it is not even printing the first print statement.

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: tryting to use switches, classes, and cant get it to work

    You are using Netbeans but how exactly are you running the code? Are you hoping Netbeans will read your mind or are you clicking on some menu option(s)? Maybe you are just click Run main project from the Run menu and your project is not the main one. Try right click on the main class in the file structure and choose run file.

  5. #5
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default Re: tryting to use switches, classes, and cant get it to work

    As a side suggestion, if you aren't needing to use switches and different classes you may want to check out enums. One enum for rank, one for suite, and just use a constructor to set the rank/suite of cards. Generally getters shouldn't do setting, for the most part, they should just return some value.

    Java Code:
    public class Card{
      Rank r;
      Suit s;
      enum Rank{ ... }
      enum Suit{ ... }
      public Card(Rank r, Suit s){ ... }
    }
    If this interests you, read here: Enum (Java Platform SE 6) and Enum Types (The Java™ Tutorials > Learning the Java Language > Classes and Objects)

Similar Threads

  1. I am having trouble with my switches.
    By Louby85 in forum New To Java
    Replies: 7
    Last Post: 08-27-2011, 03:32 AM
  2. Compiling with -d -cp switches
    By codeAJ in forum New To Java
    Replies: 8
    Last Post: 06-05-2011, 04:25 AM
  3. Using switches...
    By besweeet in forum New To Java
    Replies: 11
    Last Post: 03-04-2010, 05:48 PM
  4. help with switches
    By spots of fire in forum New To Java
    Replies: 1
    Last Post: 01-23-2010, 10:02 PM
  5. Help with switches
    By Daniel in forum New To Java
    Replies: 2
    Last Post: 07-04-2007, 09:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •