Results 1 to 2 of 2
- 02-27-2013, 03:23 PM #1
Member
- Join Date
- Feb 2013
- Posts
- 2
- Rep Power
- 0
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)
{this.PN=PlayerName;
this.hV=handValue;
this.BJ=BlackJack;
this.PS=PlayerScore;
}
}
System.out.println("Welcome to Black Jack! Player 1 enter 1 to begin the game.");
}
- 02-27-2013, 03:40 PM #2
Senior Member
- Join Date
- Jan 2013
- Location
- United States
- Posts
- 896
- Rep Power
- 1
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
- Generate a random number.
- Index into array to get the card
- Display the card.
Stay away from the inner class as you don't need it (at least not for now).
JimThe Java™ Tutorial
YAT -- Yet Another Typo
Similar Threads
-
Classes, constructors and methods
By GRGoucho in forum New To JavaReplies: 3Last Post: 02-17-2013, 06:54 PM -
Printing the superclass/constructors/methods of a class
By tehsumo in forum New To JavaReplies: 11Last Post: 03-05-2012, 11:18 AM -
Constructors & Methods
By candygirl198827 in forum New To JavaReplies: 1Last Post: 12-02-2010, 01:51 AM -
Formulas in methods or constructors?
By kyameron in forum New To JavaReplies: 11Last Post: 11-20-2010, 12:22 PM -
Calling subclassed methods from constructors
By arefeh in forum New To JavaReplies: 7Last Post: 01-22-2010, 12:22 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks