|
||
|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Please could someone check my code and tell me where the problem is? Thanks.
Java Code
/** DECK OF CARDS
* created by Arutha2321
*/
class Card { // A playing card, with variables i - number of card, color - color of card, value - value of card.
int i;
String color;
String value;
public Card (int j, StringBuffer f, StringBuffer h) { // A constructor of a card.
this.i = j;
this.color = f.toString();
this.value = h.toString();
}
public String showCard() { // A method that returns the color and value of a card in a string.
return (this.color + this.value + "\n");
}
}
class Deck { // A deck of card, with one variable cards, which is an array of instances of class Card.
Card[] cards;
public Deck() {
String[] colors = {"heart", "spade", "diamond", "club"};
String[] values = {"7", "8", "9", "10", "J", "Q", "K", "A"};
StringBuffer co = new StringBuffer();
StringBuffer va = new StringBuffer();
for (int i = 0; i < colors.length*values.length; i++) { // This creates one Card for every combination of color and value.
co.append(colors[i%colors.length]);
va.append(values[i%values.length]);
this.cards[i] = new Card(i,co,va);
}
}
public void showDeck() { //A method that prints out all of the cards in the deck.
for (int i = 0; i < colors.length*values.length; i++) {
System.out.println(this.cards[i].showCard());
}
}
}
public class DeckOfCards { // A class with the main function, that creates a deck and shows its content.
public static void main(String[] args) {
Deck deck1 = new Deck();
deck1.showDeck();
}
}
Java Code
Exception in thread "main" java.lang.NullPointerException
at Deck.<init>(DeckOfCards.java:34)
at DeckOfCard.main(DeckOfCards.java:47)
Last edited by Arutha2321; 18-11-2009 at 07:26 AM. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [SOLVED] Exception in thread "main" java.lang.NullPointerException | oscardog | Exceptions | 14 | 11-01-2010 10:36 AM |
| Exception in thread "main" java.lang.NoClassDefFoundError: AVTransmit2 | NARs | Java Networking | 1 | 25-10-2009 04:54 PM |
| Getting "AWT-EventQueue-0" java.lang.NullPointerException error | tryingtoJava | AWT / Java Swing | 9 | 22-09-2009 03:46 AM |
| Exception in thread "main" java.util.IllegalFormatWidthException: 13 | xtrive | Exceptions | 1 | 04-06-2009 03:21 PM |
| Oh dear, an "I'm a beginner" thread | Professor Spider | The Cafe | 5 | 09-04-2009 03:57 PM |
|
100 most searched terms
Search Cloud
|
| 2 dimensional arraylist java 2d arraylist java actionlistener actionlistener in java actionlistener java actionlistener jbutton addactionlistener addactionlistener java avatar hardware id convert double to integer java double format java double to int java double to integer in java double to integer java eclipse shortcut keys eclipse tutorial for beginners exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space exception in thread "main" java.lang.outofmemoryerror: java heap space format double java get mouse position java hardware id avatar java 2 dimensional arraylist java 2d arraylist java actionlistener java addactionlistener java button actionlistener java convert double to int java convert list to map java double format java double to int java double to integer java for beginner eclippse java format double java forum java forums java get mouse position java jbutton java list to map java mouse position java programming forum java programming forums java sendkeys java.lang.reflect.invocationtargetexception java.util.arraylist jbutton actionlistener jbutton java programming forums string to int java two dimensional arraylist java writing apps for ipod touch |