Mesmerale
Banned
- Messages
- 2,288
- Role
-
- Diaper Lover
- Babyfur
- Sissy
M'kay, so this code is made within Eclipse Europa. >.> I haven't updated it to Ganymede on this computer yet...
But it still works! And it's ready to be turned in tomorrow! Take a look.
The Objective
Problem: Pinochle uses a deck of 48 cards that is dealt out to the players (16 cards each). A deck has 2 of each type of card (Ace, King, Queen, Jack, 10, 9) per suit (diamonds, clubs, spades, hearts). The first step in playing the game is to count the number of points in a hand using the following rules:
The same card can be used in multiple cases but only once in each case. If a hand has two Jacks of diamonds and two Queens of spades, those cards could be used in Case #2 and Case #8 to accumulate 38 points.
INPUT: There will be 5 input lines each representing the cards in one hand. Each input line will contain 5 strings. The first string will be one-character in length and will give the trump suit (D, C, S or H) The other 4 strings name the cards in each suit the player has been dealt. The order will always be diamonds, clubs, spades and hearts. The card names used will be A (Ace), K (King), Q (Queen), J (Jack), T (Ten) and N (Nine). There will be at least one card in each suit.
OUTPUT: The score for each input hand
:down2: This is the client (driver) for the program.
:down2: This is the code for the hand itself.
:down2: This is the code for the point system (The 12 cases)
The spacing between lines sucks because the indent command is stupid, but otherwise, everything is exactly as it is in my program.
I knowwwww I should have comments in the code!! I really really really really know I should, but by the time I remembered, I'd already finished indenting it into this and I was NOT gonna go through that again. I'll add them to the posts that I reserve after this.
But it still works! And it's ready to be turned in tomorrow! Take a look.
The Objective
ACSL
American Computer Science League
Intermediate Division
ACSL Pinochle
American Computer Science League
Intermediate Division
ACSL Pinochle
Problem: Pinochle uses a deck of 48 cards that is dealt out to the players (16 cards each). A deck has 2 of each type of card (Ace, King, Queen, Jack, 10, 9) per suit (diamonds, clubs, spades, hearts). The first step in playing the game is to count the number of points in a hand using the following rules:

The same card can be used in multiple cases but only once in each case. If a hand has two Jacks of diamonds and two Queens of spades, those cards could be used in Case #2 and Case #8 to accumulate 38 points.
INPUT: There will be 5 input lines each representing the cards in one hand. Each input line will contain 5 strings. The first string will be one-character in length and will give the trump suit (D, C, S or H) The other 4 strings name the cards in each suit the player has been dealt. The order will always be diamonds, clubs, spades and hearts. The card names used will be A (Ace), K (King), Q (Queen), J (Jack), T (Ten) and N (Nine). There will be at least one card in each suit.
OUTPUT: The score for each input hand
SAMPLE INPUT
SAMPLE OUTPUT
1. D,ATKQQJ,AKQQ,KQQJN,A
1. 4
2. C,KQN,ATTQN,AQJ,ATKQJ
2. 56
3. H,ATKQJN,TJ,AQJ,ATKQJ
3. 58
4. S,KQJ,ATKQ,TKKQN,TKNN
4. 12
5. H,NNKT,NNJQ,NNAK,NTTQ
5. 0
:down2: This is the client (driver) for the program.
import java.util.Scanner;
public class PinochleClient
{
public static void main(String[] args)}
{
Scanner keyboard = new Scanner(System.in);}
String input = new String(), command = new String();
System.out.print("Please enter a command: ");
if(keyboard.next().equalsIgnoreCase("Input_Hand"))
{
do}
{
System.out.print("Please input a hand: ");} while(!(command.equalsIgnoreCase("Quit")));
input = keyboard.next();
Hand Player1 = new Hand(input);
Player1.process();
System.out.println(Player1);
System.out.print("Please enter a command: ");
command = keyboard.next();
System.out.print("*************Finished*************");
:down2: This is the code for the hand itself.
public class Hand
{
private int[] diamonds = new int[6];}
private int[] clubs = new int[6];
private int[] spades = new int[6];
private int[] hearts = new int[6];
private String hand, trump, diamondsStr, clubsStr, spadesStr, heartsStr;
private int points = 0;
public Hand(String input) { hand = input; }
public void process()
{
trump = diviUp();}
diamondsStr = diviUp();
clubsStr = diviUp();
spadesStr = diviUp();
heartsStr = diviUp();
diamonds = assign(diamondsStr);
clubs = assign(clubsStr);
spades = assign(spadesStr);
hearts = assign(heartsStr);
tallyPoints();
private String diviUp()
{
String piece = new String();}
int pos = 0;
while(pos < hand.length() && !(hand.charAt(pos) == ','))
pos++;piece = hand.substring(0, pos);
if(pos < hand.length())
hand = hand.substring(pos + 1);else
hand = "";return piece;
private int[] assign(String inputStr)
{
char card;}
int[] cardArray = new int[6];
for(int pos = 0; pos < inputStr.length(); pos++)
{
card = inputStr.charAt(pos);}
if(card == 'A')
cardArray[0] += 1;
else if(card == 'K')
cardArray[1] += 1;
else if(card == 'Q')
cardArray[2] += 1;
else if(card == 'J')
cardArray[3] += 1;
else if(card == 'T')
cardArray[4] += 1;
else if(card == 'N')
cardArray[5] += 1;
return cardArray;
private void tallyPoints()
{
if(PointSystem.doubleBook(trump, diamonds, clubs, spades, hearts) == true)}
points += 150;if(PointSystem.twins(diamonds, spades) == true)
points += 30;if(PointSystem.aces(diamonds, clubs, spades, hearts) == true)
points += 10;if(PointSystem.kings(diamonds, clubs, spades, hearts) == true)
points += 8;if(PointSystem.doubleAces(diamonds, clubs, spades, hearts) == true)
points += 100;if(PointSystem.doubleKings(diamonds, clubs, spades, hearts) == true)
points += 80;if(PointSystem.singleBook(trump, diamonds, clubs, spades, hearts) > 0)
points += (50 * PointSystem.singleBook(trump, diamonds, clubs, spades, hearts));if(PointSystem.wedding(diamonds, spades) == true)
points += 4;if(PointSystem.queens(diamonds, clubs, spades, hearts) == true)
points += 6;if(PointSystem.jacks(diamonds, clubs, spades, hearts) == true)
points += 4;if(PointSystem.doubleQueens(diamonds, clubs, spades, hearts) == true)
points += 60;if(PointSystem.doubleJacks(diamonds, clubs, spades, hearts) == true)
points += 40;
public String toString() { return "Player's Score: " + points; }
:down2: This is the code for the point system (The 12 cases)
public class PointSystem
{
static public boolean doubleBook(String trump, int[] diamonds, int[] clubs, int[] spades, int[] hearts)}
{
if(trump.equals("D") && diamonds[0] == 2 && diamonds[1] == 2 && diamonds[2] == 2}
&& diamonds[3] == 2 && diamonds[4] == 2 && diamonds[5] == 2)
return true;else if(trump.equals("C") && clubs[0] == 2 && clubs[1] == 2 && clubs[2] == 2
&& clubs[3] == 2 && clubs[4] == 2 && clubs[5] == 2)
return true;else if(trump.equals("S") && spades[0] == 2 && spades[1] == 2 && spades[2] == 2
&& spades[3] == 2 && spades[4] == 2 && spades[5] == 2)
return true;else if(trump.equals("H") && hearts[0] == 2 && hearts[1] == 2 && hearts[2] == 2
&& hearts[3] == 2 && hearts[4] == 2 && clubs[5] == 2)
return true;return false;
static public boolean twins(int[] diamonds, int[] spades)
{
if(diamonds[3] == 2 && spades[2] == 2)}
return true;return false;
static public boolean aces(int[] diamonds, int[] clubs, int[] spades, int[] hearts)
{
if(diamonds[0] > 0 && clubs[0] > 0 && spades[0] > 0 && hearts[0] > 0)}
return true;return false;
static public boolean kings(int[] diamonds, int[] clubs, int[] spades, int[] hearts)
{
if(diamonds[1] > 0 && clubs[1] > 0 && spades[1] > 0 && hearts[1] > 0)}
return true;return false;
static public boolean doubleAces(int[] diamonds, int[] clubs, int[] spades, int[] hearts)
{
if(diamonds[0] == 2 && clubs[0] == 2 && spades[0] == 2 && hearts[0] == 2)}
return true;return false;
static public boolean doubleKings(int[] diamonds, int[] clubs, int[] spades, int[] hearts)
{
if(diamonds[1] == 2 && clubs[1] == 2 && spades[1] == 2 && hearts[1] == 2)}
return true;return false;
static public int singleBook(String trump, int[] diamonds, int[] clubs, int[] spades, int[] hearts)
{
int count = 0;}
if(!(trump.equals("D")) && diamonds[0] > 0 && diamonds[1] > 0 && diamonds[2] > 0
&& diamonds[3] > 0 && diamonds[4] > 0 && diamonds[5] > 0)
count += 1;if(!(trump.equals("C")) && clubs[0] > 0 && clubs[1] > 0 && clubs[2] > 0
&& clubs[3] > 0 && clubs[4] > 0 && clubs[5] > 0)
count += 1;if(!(trump.equals("S")) && spades[0] > 0 && spades[1] > 0 && spades[2] > 0
&& spades[3] > 0 && spades[4] > 0 && spades[5] > 0)
count += 1;if(!(trump.equals("H")) && hearts[0] > 0 && hearts[1] > 0 && hearts[2] > 0
&& hearts[3] > 0 && hearts[4] > 0 && clubs[5] > 0)
count += 1;return count;
static public boolean wedding(int[] diamonds, int[] spades)
{
if(diamonds[3] > 0 && spades[2] > 0)}
return true;return false;
static public boolean queens(int[] diamonds, int[] clubs, int[] spades, int[] hearts)
{
if(diamonds[2] > 0 && clubs[2] > 0 && spades[2] > 0 && hearts[2] > 0)}
return true;return false;
static public boolean jacks(int[] diamonds, int[] clubs, int[] spades, int[] hearts)
{
if(diamonds[3] > 0 && clubs[3] > 0 && spades[3] > 0 && hearts[3] > 0)}
return true;return false;
static public boolean doubleQueens(int[] diamonds, int[] clubs, int[] spades, int[] hearts)
{
if(diamonds[2] == 2 && clubs[2] == 2 && spades[2] == 2 && hearts[2] == 2)}
return true;return false;
static public boolean doubleJacks(int[] diamonds, int[] clubs, int[] spades, int[] hearts)
{
if(diamonds[3] == 2 && clubs[3] == 2 && spades[3] == 2 && hearts[3] == 2)}
return true;return false;
The spacing between lines sucks because the indent command is stupid, but otherwise, everything is exactly as it is in my program.
I knowwwww I should have comments in the code!! I really really really really know I should, but by the time I remembered, I'd already finished indenting it into this and I was NOT gonna go through that again. I'll add them to the posts that I reserve after this.
Last edited: