I did this using ArrayList<String> and my tests worked. Meaning I was able to read the strings in a different class through my constructor. However I want to use a string array because it will be easier to handle when I finish the program. I will send each players poker hand in and figure out who is the winner instead of putting it all onto a ArrayList and having to iterate through it. However whenever I did my check I am just printing null.
PokerFile class
void separateHands(String cards) { //ArrayList<String>playerOne = new ArrayList<String>(); //ArrayList<String>playerTwo = new ArrayList<String>(); String[] playerOne = new String[10]; String[] playerTwo = new String[10]; String[] parts = cards.split(" "); for(int i=0;i<5;i++) { playerOne[i]=parts[i]; //playerOne.add(parts[i]); } for(int j=5;j<10;j++) { playerTwo[j]=parts[j]; //playerTwo.add(parts[j]); } new WinningHand(playerOne,playerTwo); }
ignore the boolean methods I was just building the structure of the program. The print file is what is outputting this:
null
null
null
null
null
null
public class WinningHand extends PokerFile { //ArrayList<String> p1 = new ArrayList<String>(); //ArrayList<String> p2 = new ArrayList<String>(); String[] p1 = new String[6]; String[] p2 = new String[6]; WinningHand(String[] p1,String[] p2) { this.p1=p1; this.p2=p2; } WinningHand() { } boolean pair(ArrayList<String> hand) { return true; } boolean threeOfaKind(ArrayList<String> hand) { return true; } boolean twoPair(ArrayList<String> hand) { return true; } boolean flush(ArrayList<String> hand) { return true; } boolean fullHouse(ArrayList<String> hand) { return true; } boolean fourOfaKind(ArrayList<String> hand) { return true; } boolean straightFlush(ArrayList<String> hand) { return true; } boolean royalFlush(ArrayList<String> hand) { return true; } void print() { for(String s: p2) { System.out.println(s); } } public static void main(String[] args) { PokerFile poker = new PokerFile(); WinningHand hand = new WinningHand(); poker.readFile(); hand.print(); } }