ok well i keep getting this nullpointexcept ion error, can someone tell me whats wrong with it. here is my code:
Code:
/**
* The purpose of this program is to recieve the input from the text file.
* Then shuffle the cards according to that input
*
* @author Brandon Morales
* @version 1.0
*/
import java.util.Scanner;
import java.io.*;
public class CardShuffle{
public static String [] finalDeck = new String [52];
public static String [] westHand = new String [ 13 ];
public static String [] suit = {"C" , "D" , "H" , "S"};
public static String [] deck = {"2" , "3", "4" , "5" , "6" , "7" , "8" , "9" , "T" , "J" , "Q" , "K" , "A" };
public static void main(String [] args) throws IOException{
Scanner textIn = new Scanner (new File ("shuffler.txt"));
while (textIn.hasNext()){
String [] westHand = new String [ 13 ];
String [] deck = {"2" , "3", "4" , "5" , "6" , "7" , "8" , "9" , "T" , "J" , "Q" , "K" , "A" };
String [] suit = {"C" , "D" , "H" , "S"};
boolean loop = true;
int hand = 0;
for (int x = 0; x < suit.length; x++){
for (int y = 0; y < deck.length; y++){
finalDeck [ x * deck.length + y] = (deck [y] + " of " + suit [x]);
}
}
String line = textIn.nextLine();
String [] details = line.split(" " , 10);
for (int j = 0; j < details.length; j++){
shuffle(Integer.parseInt(details[j]));
}
System.out.println("************West*Hand*******");
for (int i = 0; i < finalDeck.length; i ++){
if ( ( i + 1 ) % 4 == 0 ){
westHand [ hand ] = finalDeck [ i ];
hand ++;
}
}
System.out.println();
hand = 0;
sorter();
System.out.println("**************************");
}//text input and print
}//Main method
/**
* The purpose of this method is to take the input of the text and put all the index numbers of the cards
* and put them in a new array then, and then shuffle the rest of the cards putting one up and one down.
*
* @param shufflePattern The input of the text file
*/
public static void shuffle (int shufflePattern){
String [] choosen = new String [52/shufflePattern];
String [] leftOver = new String [52 - choosen.length];
String [] top = new String [leftOver.length/2];
String [] bottom = new String [(leftOver.length/2) + (leftOver.length%2)];
int deck2 = 0;
int counter = 0;
int topCounter = top.length - 1;
int bottomCounter = 0;
int finalCount = 0;
int splitDeck2 = 0;
boolean loop = true;
for (int x = 0; x < finalDeck.length; x++){
if ((x + 1) % shufflePattern == 0){
choosen[counter] = finalDeck[x];
counter ++;
}
else {
leftOver[deck2] = finalDeck[x];
deck2++;
}
}
for (int i = 0; i < leftOver.length; i++){
if ((i + 1) % 2 == 0){
top [topCounter] = leftOver[i];
topCounter--;
}
else {
bottom [bottomCounter] = leftOver[i];
bottomCounter++;
}
}
for (int i = 0; i < top.length; i ++) {
finalDeck[finalCount] = top [i];
finalCount++;
}
for (int i = 0; i < choosen.length; i ++) {
finalDeck[finalCount] = choosen [i];
finalCount++;
}
for (int i = 0; i < bottom.length; i ++) {
finalDeck[finalCount] = bottom [i];
finalCount++;
}
}//shuffle method
public static void sorter (){
String [] hearts = new String [13];
String [] diamonds = new String [13];
String [] spades = new String [13];
String [] clubs = new String [13];
int heart =0;
int spade = 0;
int club = 0;
int diamond = 0;
char value;
for (int i = 0; i < westHand.length; i ++){
value = westHand[i].charAt(westHand[i].length()-1);
if (value == 'H'){
hearts[heart] = westHand[i];
heart ++;
}
else if (value == 'S'){
spades[spade] = westHand[i];
spade ++;
}
else if (value == 'D'){
diamonds[diamond] = westHand[i];
diamond ++;
}
else if (value == 'C'){
clubs [club] = westHand[i];
club ++;
}
}
for (int i = 0; i < spade; i ++){
System.out.println(spades[i]);
}
for (int i = 0; i < heart; i ++){
System.out.println(hearts[i]);
}
for (int i = 0; i < diamond; i ++){
System.out.println(diamonds[i]);
}
for (int i = 0; i < club; i ++){
System.out.println(clubs[i]);
}
}
}//CardShuffle Class
Comment