|
||
|
|||||||
![]() |
|
|
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 06: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 | 16 | 27-08-2010 08:30 PM |
| Getting "AWT-EventQueue-0" java.lang.NullPointerException error | tryingtoJava | AWT / Java Swing | 10 | 14-05-2010 02:42 PM |
| Exception in thread "main" java.util.IllegalFormatWidthException: 13 | xtrive | Exceptions | 2 | 23-03-2010 05:38 AM |
| Exception in thread "main" java.lang.NoClassDefFoundError: AVTransmit2 | NARs | Java Networking | 1 | 25-10-2009 03:54 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
|
| 2d arraylist java actionlistener actionlistener in java actionlistener java addactionlistener addactionlistener in java addactionlistener java applications of oops could not create java virtual machine xp double format java double to int 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.nullpointerexception exception in thread "main" java.lang.outofmemoryerror: java heap space format double java get mouse position java java 2d arraylist java actionlistener java addactionlistener java convert list to map java double format java double formatting java double to int java double to integer java format double java forum java forums java get mouse position java list to map java mouse position java programming forum java programming forums java programming help java sendkeys java two dimensional arraylist java.lang.classformaterror: truncated class file java.lang.outofmemoryerror: java heap space java.util.arraylist jbutton actionlistener jtextarea font jtextfield font size jxl.read.biff.biffexception: unable to recognize ole stream programming mutators and generics two dimensional arraylist java writing ipod apps |