# Advanced Data Structure On a teacher’s salary, it is necessa...

## Solution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import java.util.*;

public class Poker {

int count = -5;
ArrayList<ArrayList<String>> players;

// Constructor
public Poker(int numPlayers) {
players = new ArrayList<ArrayList<String>>();
for (int i=0; i<numPlayers; i++) {
}
}

if (count < 0) {
for (int i=0; i<players.size(); i++) {
}
} else {
int i = count / 5;
}
count++;
}

// Method to return hand name
private String handName(int i) {
i = scoreHand(i);
if (i == 15) {
return "Dinner Party";
} else if (i == 14) {
return "Politics";
} else if (i == 13) {
return "Orgy";
} else if (i == 12) {
return "Kingdom";
} else if (i == 11) {
return "Homosapiens";
} else if (i == 10) {
return "Overfull House";
} else if (i == 9) {
return "Triplets";
} else if (i == 8) {
return "Flush";
} else if (i == 7) {
return "Odd";
} else if (i == 6) {
return "Even";
} else if (i == 5) {
return "Monarchy";
} else if (i == 4) {
return "3 Pair";
} else if (i == 3) {
return "Monochromatic";
} else if (i == 2) {
return "Swingers";
} else if (i == 1) {
return "Rainbow";
} else {
return "Non-rainbow";
}
}

// Method to score hand
private int scoreHand(int i) {
List<String> c = players.get(i).subList(0,5);
List<String> p = players.get(i).subList(5,10);
if (dinnerParty(c,p)) {
return 15;
} else if (politics(c,p)) {
return 14;
} else if (orgy(c,p)) {
return 13;
} else if (kingdom(c,p)) {
return 12;
} else if (homosapiens(c,p)) {
return 11;
} else if (overfullHouse(c,p)) {
return 10;
} else if (triplets(c,p)) {
return 9;
} else if (flush(c,p)) {
return 8;
} else if (odd(c,p)) {
return 7;
} else if (even(c,p)) {
return 6;
} else if (monarchy(c,p)) {
return 5;
} else if (threePair(c,p)) {
return 4;
} else if (monochromatic(c,p)) {
return 3;
} else if (swingers(c,p)) {
return 2;
} else if (rainbow(c,p)) {
return 1;
} else if (nonrainbow(c,p)) {
return 0;
}
return -1;
}

// Method to score all hands
public void scoreHands() {
ArrayList<String> playersCopy = new ArrayList<String>();
for (int i = 0; i < players.size(); i++) {
}
int rank = 1;
while(playersCopy.size() > 0) {
int bestScore = -1;
ArrayList<String> best = new ArrayList<String>();
for (String s: playersCopy) {
int i = Integer.parseInt(s);
if (scoreHand(i) > bestScore) {
bestScore = scoreHand(i);
best = new ArrayList<String>();
} else if (scoreHand(i) == bestScore) {
}
}
if (best.size() > 1) {
System.out.println("TIE");
}
for (String s: best) {
int i = Integer.valueOf(s);
System.out.println("Rank "+rank+": Player "+(i+1)+" -- Hand: "+handName(i));
playersCopy.remove(s);
}
rank++;
}
}

// Dinner Party: All your cards are suited kings and queens
private boolean dinnerParty(List<String> c, List<String> p) {
int countC = 0;
for (String s: c) {
if ((s.charAt(0) == 'K') || (s.charAt(0) == 'Q')) {
countC++;
}
}
int countP = 0;
for (String s: p) {
if ((s.charAt(0) == 'K') || (s.charAt(0) == 'Q')) {
countP++;
}
if (countP == 3) {
break;
}
}
int count = countC + countP;
return (count >= 6 && countC >= 3);
}

// Politics: You hold two Monarchies
private boolean politics(List<String> c, List<String> p) {
int[] countC = new int[4];
for (String s: c) {
if ((s.charAt(0) == 'K') || (s.charAt(0) == 'Q') || (s.charAt(0) == 'J')) {
if (s.charAt(1) == 'h') {
countC[0]++;
} else if (s.charAt(1) == 'd') {
countC[1]++;
} else if (s.charAt(1) == 'c') {
countC[2]++;
} else if (s.charAt(1) == 's') {
countC[3]++;
}
}
}
int[] countP = new int[4];
for (String s: p) {
if ((s.charAt(0) == 'K') || (s.charAt(0) == 'Q') || (s.charAt(0) == 'J')) {
if (s.charAt(1) == 'h') {
countP[0]++;
} else if (s.charAt(1) == 'd') {
countP[1]++;
} else if (s.charAt(1) == 'c') {
countP[2]++;
} else if (s.charAt(1) == 's') {
countP[3]++;
}
}
}
int count = 0;
for (int i = 0; i < 4; i++) {
if (countC[i] + countP[i] >= 3) {
count++;
}
}
return count >= 2;
}

// Orgy: All your cards are Jacks and Queens
private boolean orgy(List<String> c, List<String> p) {
int countC = 0;
for (String s: c) {
if ((s.charAt(0) == 'Q') || (s.charAt(0) == 'J')) {
countC++;
}
}
int countP = 0;
for (String s: p) {
if ((s.charAt(0) == 'Q') || (s.charAt(0) == 'J')) {
countP++;
}
if (countP == 3) {
break;
}
}
int count = countC + countP;
return count >= 6;
}

// Kingdom: Monarchy + the remaining cards are of the same
private boolean kingdom(List<String> c, List<String> p) {
int[] countC = new int[4];
int[] countC2 = new int[4];
for (String s: c) {
if ((s.charAt(0) == 'K') || (s.charAt(0) == 'Q') || (s.charAt(0) == 'J')) {
if (s.charAt(1) == 'h') {
countC...

By purchasing this solution you'll be able to access the following files:
Solution.PNG and Solution.java.

# 50% discount

Hours
Minutes
Seconds
\$40.00 \$20.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

### Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.