hey, i am doing a sterling game java program. its a simple card game where you draw 1 card and add the number to your previous card. i made the program but i need an arraylist to check the previous card drawn to see if you get the number twice in a row.
my program so far:
import java.util.*;
import javax.swing.*;
public class sterling {
public sterling() {
super();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int input = 0;
int playercard = 0;
int dealercard = 0;
JOptionPane.sho wMessageDialog( null, "Welcome to Sterling Game");
do
{
Random r = new Random();
int card = r.nextInt(13);
Random t = new Random();
int suit = t.nextInt(4);
String card2 = "";
String suit2 = "";
if (suit== 0)
suit2 = "Spades";
if (suit== 1)
suit2 = "Diamonds";
if (suit== 2)
suit2 = "Clubs";
if (suit== 3)
suit2 = "Hearts";
if (card== 0)
{
card = 1;
card2 = "Ace";
}
if (card== 1)
card2 = "2";
if (card== 2)
card2 = "3";
if (card== 3)
card2 = "4";
if (card== 4)
card2 = "5";
if (card== 5)
card2 = "6";
if (card== 6)
card2 = "7";
if (card== 7)
card2 = "8";
if (card== 8)
card2 = "9";
if (card== 9)
card2 = "10";
if (card== 10)
card2 = "Jack";
if (card== 11)
card2 = "Queen";
if (card== 12)
card2 = "King";
input=Integer.p arseInt(JOption Pane.showInputD ialog(null, "Main Menu \n" +
"1. Draw a card \n" +
"2 Quit the game \n"));
if (input==1)
JOptionPane.sho wMessageDialog( null, "" + card2 + " of " + suit2);
playercard = playercard + card + 1;
JOptionPane.sho wMessageDialog( null, "Your total is: " + playercard);
}while(input != 2);
}
}
help would be appreciated. i know i might get the same card and suit twice, but thats not a problem
my program so far:
import java.util.*;
import javax.swing.*;
public class sterling {
public sterling() {
super();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int input = 0;
int playercard = 0;
int dealercard = 0;
JOptionPane.sho wMessageDialog( null, "Welcome to Sterling Game");
do
{
Random r = new Random();
int card = r.nextInt(13);
Random t = new Random();
int suit = t.nextInt(4);
String card2 = "";
String suit2 = "";
if (suit== 0)
suit2 = "Spades";
if (suit== 1)
suit2 = "Diamonds";
if (suit== 2)
suit2 = "Clubs";
if (suit== 3)
suit2 = "Hearts";
if (card== 0)
{
card = 1;
card2 = "Ace";
}
if (card== 1)
card2 = "2";
if (card== 2)
card2 = "3";
if (card== 3)
card2 = "4";
if (card== 4)
card2 = "5";
if (card== 5)
card2 = "6";
if (card== 6)
card2 = "7";
if (card== 7)
card2 = "8";
if (card== 8)
card2 = "9";
if (card== 9)
card2 = "10";
if (card== 10)
card2 = "Jack";
if (card== 11)
card2 = "Queen";
if (card== 12)
card2 = "King";
input=Integer.p arseInt(JOption Pane.showInputD ialog(null, "Main Menu \n" +
"1. Draw a card \n" +
"2 Quit the game \n"));
if (input==1)
JOptionPane.sho wMessageDialog( null, "" + card2 + " of " + suit2);
playercard = playercard + card + 1;
JOptionPane.sho wMessageDialog( null, "Your total is: " + playercard);
}while(input != 2);
}
}
help would be appreciated. i know i might get the same card and suit twice, but thats not a problem
Comment