Results 1 to 2 of 2
  1. #1
    mjfitches is offline Member
    Join Date
    Feb 2013
    Rep Power

    Default Help with arrays and methods and constructors

    I have been set an assignment to design a simple blackjack game for 2 players and to assign values for each card dealt to them, based on a points system which each card is worth. Due to being unwell and missing a lot of the lectures I am finding this really difficult! Anybody have any advice on my code?

    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package javaapplication23;

    import java.util.Random;

    public class JavaApplication23 {
    class pickRand{
    public static String get(String[] array) {
    int rnd = generator.nextInt(array.length);
    return array[rnd];
    public static void main(String[] args) {
    String [] card = new String [52];
    String[] cards = { "Ace","Ace","Ace","Ace", "2","2","2","2", "3","3","3","3", "4","4","4","4", "5","5","5","5", "6","6","6","6", "7","7","7","7", "8","8","8","8", "9","9","9","9", "10","10","10","10", "Jack","Jack","Jack","Jack", "Queen","Queen","Queen","Queen", "King","King","King","King" };
    String ret = pickRand.get(cards);

    static class Player{
    int PN;
    int hV;
    boolean BJ;
    int PS;
    Player(int PlayerName, int handValue, boolean BlackJack, int PlayerScore)
    System.out.println("Welcome to Black Jack! Player 1 enter 1 to begin the game.");


  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Northern Virginia, United States
    Rep Power

    Default Re: Help with arrays and methods and constructors

    First, you should include your code in [code][/code] tags to make it easier for folks to read.

    Second, have you discussed this with your instructor. S/he should be able and willing to help you since you have been ill.

    As far as your code goes, just start slow. First, simply write some code to

    1. Generate a random number.
    2. Index into array to get the card
    3. Display the card.

    Stay away from the inner class as you don't need it (at least not for now).

    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Classes, constructors and methods
    By GRGoucho in forum New To Java
    Replies: 3
    Last Post: 02-17-2013, 06:54 PM
  2. Replies: 11
    Last Post: 03-05-2012, 11:18 AM
  3. Constructors & Methods
    By candygirl198827 in forum New To Java
    Replies: 1
    Last Post: 12-02-2010, 01:51 AM
  4. Formulas in methods or constructors?
    By kyameron in forum New To Java
    Replies: 11
    Last Post: 11-20-2010, 12:22 PM
  5. Calling subclassed methods from constructors
    By arefeh in forum New To Java
    Replies: 7
    Last Post: 01-22-2010, 12:22 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