473,394 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

arraylist help

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.showMessageDialog(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.parseInt(JOptionPane.showInputDialog (null, "Main Menu \n" +
"1. Draw a card \n" +
"2 Quit the game \n"));
if (input==1)
JOptionPane.showMessageDialog(null, "" + card2 + " of " + suit2);
playercard = playercard + card + 1;
JOptionPane.showMessageDialog(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
Mar 1 '07 #1
1 1436
r035198x
13,262 8TB
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.showMessageDialog(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.parseInt(JOptionPane.showInputDialog (null, "Main Menu \n" +
"1. Draw a card \n" +
"2 Quit the game \n"));
if (input==1)
JOptionPane.showMessageDialog(null, "" + card2 + " of " + suit2);
playercard = playercard + card + 1;
JOptionPane.showMessageDialog(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
Please use code tags when posting code.
Use the design used here. It is the correct way to design such a program
Mar 1 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Stephen | last post by:
I have got an event below to remove items from an arraylist and then to rebind the arraylist to the datagrid subsequently deleting the appropriate row. My problem is that my code makes sense and I...
3
by: Stephen | last post by:
I've been working on some code which will hopefully allow me to transfer the contents of an arraylist on one page over to another page. The Arraylist is held in the viewstate object as it is...
2
by: Stephen | last post by:
I am trying to delete a row in a datagrid on the onclick of a asp:ButtonColumn. The datagrid is created from the items in an arraylist so what im trying to do is remove the item from the array and...
3
by: Stephen | last post by:
I was wondering if someone can help me with an web application design problem. I have a aspx page which builds up an arraylist called addresses and outputs the values in the arraylist items to a...
9
by: Leon | last post by:
I have a webform in which when the user press generate button the form generate six unique ramdon numbers, the user can also type these six numbers in manually in any order. however, the user can...
7
by: Dave | last post by:
Hi all, I have... using System.Collections; namespace MyApp.Templates { public class MyPage : System.Web.UI.Page { ArrayList MyArray = new ArrayList();
6
by: gane kol | last post by:
Hi, I have a code that creates a datatable from an arraylist, but i am getting an error in casting in for (int intRow = 0; intRow < alLCPlist.Count; intRow++) { DataRow drow =...
6
by: GrandpaB | last post by:
While writing this plea for help, I think I solved my dilemma, but I don't know why the problem solving statement is necessary. The inspiration for the statement came from an undocumented VB...
18
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the...
6
by: fniles | last post by:
I am using VB.NET 2003 and a socket control to receive and sending data to clients. As I receive data in 1 thread, I put it into an arraylist, and then I remove the data from arraylist and send it...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.