Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jan 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Java help please

    Hi I'm new to Java progamming and am very afraid of it right now. I only had C++ for a semester so far. Could someone please help me understand some of the terms used in Java?

    What is a package?

  • #2
    New to the CF scene
    Join Date
    Jan 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    okay. here is what I have so far. It works but is not nearly as specific as it needs to be.

    Code:
    /*
     * Kailey Mattheisen
     * Card.java is a program deals 5 playing cards at random
     */
    
    //package card;
    
    /**
     *
     * @author MaximumKay
     */
    
    import java.util.Random;
    
    public class Card {
    
        /**
         * pulls out random values for the 5 cards drawn from  52 card deck in a row without being replaced.
         */
        public static void main(String[] args) {
            Random generator = new Random();
            int num1, num2, num3, num4, num5;
    
            num1 = generator.nextInt();
    
            num2 = generator.nextInt();
    
            num3 = generator.nextInt();
    
            num4 = generator.nextInt();
    
            num5 = generator.nextInt();
    
            System.out.println("Cards dealt to hand: " + num1 + num2 + num3 + num4 + num5);
        }
    
    }
    This is my assignment.

    Design and implement a class called Card that represents a standard playing card. Each card has a suit and a face value. Create a program that deals five random cards.

    okay. so I fixed a couple things. my next question is if I impliment if then statements into my program so that I can have someone draw a Jack, king, or queen, do I have to put it for every print statement?

    Code:
    import java.util.Random;
    
    public class Card {
    
        /**
         * pulls out random values for the 5 cards drawn from  52 card deck in a row without being replaced.
         */
        public static void main(String[] args) {
            Random generator = new Random();
            int num1, num2, num3, num4, num5;
    
    
            System.out.println("Cards dealt to your hand");
            
            num1 = generator.nextInt(10) + 1;
            System.out.println("Card 1: " + num1);
    
            num2 = generator.nextInt(10) + 1;
            System.out.println("Card 2: " + num2);
    
            num3 = generator.nextInt(10) + 1;
            System.out.println("Card 3: " + num3);
    
            num4 = generator.nextInt(10) + 1;
            System.out.println("Card 4: " + num4);
    
            num5 = generator.nextInt(10) + 1;
            System.out.println("Card 5: " + num5);
            
        }
    
    }
    Last edited by ShaneC; 01-29-2011 at 09:35 PM. Reason: Merged Triple Posts + Added Code tags

  • #3
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Maximum Kay View Post
    okay. so I fixed a couple things. my next question is if I impliment if then statements into my program so that I can have someone draw a Jack, king, or queen, do I have to put it for every print statement?

    import java.util.Random;

    public class Card {

    /**
    * pulls out random values for the 5 cards drawn from 52 card deck in a row without being replaced.
    */
    public static void main(String[] args) {
    Random generator = new Random();
    int num1, num2, num3, num4, num5;


    System.out.println("Cards dealt to your hand");

    num1 = generator.nextInt(10) + 1;
    System.out.println("Card 1: " + num1);

    num2 = generator.nextInt(10) + 1;
    System.out.println("Card 2: " + num2);

    num3 = generator.nextInt(10) + 1;
    System.out.println("Card 3: " + num3);

    num4 = generator.nextInt(10) + 1;
    System.out.println("Card 4: " + num4);

    num5 = generator.nextInt(10) + 1;
    System.out.println("Card 5: " + num5);

    }

    }
    try this:

    http://download.oracle.com/javase/tutorial/
    http://download.oracle.com/javase/tu...ava/index.html

    btw use a Array to store cards and a loop to create and print them.

    best regards

  • Users who have thanked oesxyl for this post:

    Maximum Kay (01-31-2011)

  • #4
    New to the CF scene
    Join Date
    Jan 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Cool! I will try that! thank you!


  •  

    Posting Permissions

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