Skip to content

Commit

Permalink
Auto stash before revert of "Gone Gold"
Browse files Browse the repository at this point in the history
  • Loading branch information
AJarjis committed Jan 30, 2018
1 parent ac62cc9 commit fe3a81f
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 320 deletions.
Binary file modified recentGameFile.ser
Binary file not shown.
20 changes: 10 additions & 10 deletions src/question1/Card.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** ***************************************************************************
/******************************************************************************
*
* File : Card.java
*
Expand All @@ -8,7 +8,7 @@
*
* Author : Ali Jarjis
*
***************************************************************************** */
******************************************************************************/
package question1;

import java.io.Serializable;
Expand Down Expand Up @@ -72,7 +72,7 @@ public Rank getPrevious() {
* @return Equated value of the rank.
*/
public int getVALUE() {
return VALUE;
return this.VALUE;
}
};

Expand Down Expand Up @@ -125,19 +125,19 @@ public int compareTo(Card card) {
/**
* Retrieves the rank of a card.
*
* @return rank Card rank
* @return Card rank
*/
public Rank getRank() {
return rank;
return this.rank;
}

/**
* Retrieves the suit of a card.
*
* @return suit Card suit
* @return Card suit
*/
public Suit getSuit() {
return suit;
return this.suit;
}

/**
Expand All @@ -148,15 +148,15 @@ public Suit getSuit() {
*/
@Override
public String toString() {
return rank + " OF " + suit;
return this.rank + " OF " + this.suit;
}

/**
* Sums the value of two cards.
*
* @param card1 Card to be added
* @param card2 Second card to be added
* @return Sum value of the two cards
* @return Sum value of the two cards
*/
public static int sum(Card card1, Card card2) {
return card1.rank.getVALUE() + card2.rank.getVALUE();
Expand All @@ -167,7 +167,7 @@ public static int sum(Card card1, Card card2) {
*
* @param card1 Card to be added
* @param card2 Second card to be added
* @return - true if cards equal 21, - false otherwise
* @return true if cards equal 21, false otherwise
*/
public static boolean isBlackjack(Card card1, Card card2) {
final int BLACKJACK = 21;
Expand Down
21 changes: 11 additions & 10 deletions src/question1/Deck.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,20 +157,19 @@ public Iterator<Card> secondCardIterator() {
return new SecondCardIterator();
}

//TODO: Save serializable in SecondCardIterator order
/**
* De-serialises the deck of cards
*
* @param stream deck to de-serialise
* @throws ClassNotFoundException if class of serialised object could not be
* found
* @throws IOException if an I/O error occurs
* @throws ClassNotFoundException if class of serialised object could
* not be found
* @throws IOException if an I/O error occurs
*/
private void readObject(ObjectInputStream stream)
throws ClassNotFoundException, IOException {
stream.defaultReadObject();

//deckCards = (LinkedList<Card>) stream.readObject();
deckCards = (LinkedList<Card>) stream.readObject();
}

/**
Expand All @@ -183,14 +182,16 @@ private void writeObject(ObjectOutputStream stream)
throws IOException {
stream.defaultWriteObject();

// Saves deck in secondCardIterator order
LinkedList<Card> secondCardDeck = new LinkedList<>();
Iterator<Card> secondCardIterator = this.secondCardIterator();


// Adds every second card to the new list to be saved
while (secondCardIterator.hasNext()) {
Card c = secondCardIterator.next();

stream.writeObject(c);
secondCardDeck.add(c);
}

stream.writeObject(secondCardDeck);

}

Expand Down Expand Up @@ -240,7 +241,7 @@ public static void main(String[] args) {

Deck storedDeck = (Deck) readFromFile(file);

System.out.println("Stored Deck:");
System.out.println("Stored Deck in SecondCardIterator Order:");
for (Card c : storedDeck) {
System.out.println(c);
}
Expand Down
6 changes: 3 additions & 3 deletions src/question2/BlackjackTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public static void gameMenu(BlackjackTable table) {
break;
case 3: // Save Game
saveGame(table);
playAgain = false;
break;
case 4: // Quit playing
default:
Expand Down Expand Up @@ -221,7 +222,7 @@ public static void humanGame() {

// User input code:
Scanner userScanner = new Scanner(System.in);
boolean playAgain = false;
boolean playAgain = true;
int rounds = 1;

do {
Expand All @@ -238,13 +239,13 @@ public static void humanGame() {

switch (userChoice) {
case 1: // Continue playing
playAgain = true;
break;
case 2: // Load game
table = loadGame(table);
break;
case 3: // Save game
saveGame(table);
playAgain = false;
break;
case 4: // Quit playing
default:
Expand Down Expand Up @@ -290,7 +291,6 @@ public static void advancedGame() {
BlackjackTable table = new BlackjackTable(players);

gameMenu(table);
// TODO: Print average profit/loss per deck
}

/**
Expand Down
108 changes: 10 additions & 98 deletions src/question2/Card.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** ***************************************************************************
/******************************************************************************
*
* File : Card.java
*
Expand All @@ -8,13 +8,11 @@
*
* Author : Ali Jarjis
*
***************************************************************************** */
******************************************************************************/
package question2;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
*
Expand Down Expand Up @@ -72,7 +70,7 @@ public Rank getPrevious() {
* @return Equated value of the rank.
*/
public int getVALUE() {
return VALUE;
return this.VALUE;
}
};

Expand Down Expand Up @@ -125,19 +123,19 @@ public int compareTo(Card card) {
/**
* Retrieves the rank of a card.
*
* @return rank Card rank
* @return Card rank
*/
public Rank getRank() {
return rank;
return this.rank;
}

/**
* Retrieves the suit of a card.
*
* @return suit Card suit
* @return Card suit
*/
public Suit getSuit() {
return suit;
return this.suit;
}

/**
Expand All @@ -148,15 +146,15 @@ public Suit getSuit() {
*/
@Override
public String toString() {
return rank + " OF " + suit;
return this.rank + " OF " + this.suit;
}

/**
* Sums the value of two cards.
*
* @param card1 Card to be added
* @param card2 Second card to be added
* @return Sum value of the two cards
* @return Sum value of the two cards
*/
public static int sum(Card card1, Card card2) {
return card1.rank.getVALUE() + card2.rank.getVALUE();
Expand All @@ -167,7 +165,7 @@ public static int sum(Card card1, Card card2) {
*
* @param card1 Card to be added
* @param card2 Second card to be added
* @return - true if cards equal 21, - false otherwise
* @return true if cards equal 21, false otherwise
*/
public static boolean isBlackjack(Card card1, Card card2) {
final int BLACKJACK = 21;
Expand Down Expand Up @@ -239,90 +237,4 @@ public int compare(Card card1, Card card2) {
return suitDiff;
}
}

/**
* Main method for testing methods of the card class
*
* @param args the command line arguments
*/
public static void main(String[] args) {
/*
Practice cards for testing, also have the added purpose of
testing the card and enum constructors.
*/
Rank myRank1 = Rank.QUEEN;
Suit mySuit1 = Suit.CLUBS;
Card myCard1 = new Card(myRank1, mySuit1);

Rank myRank2 = Rank.QUEEN;
Suit mySuit2 = Suit.SPADES;
Card myCard2 = new Card(myRank2, mySuit2);

/* Test for suit enums */
System.out.println("All Suits: ");
for (Suit s : Suit.values()) {
System.out.println(s);
}

/* Test for rank enums with values */
System.out.println("\nAll Ranks: ");
for (Rank r : Rank.values()) {
System.out.println(r + "(" + r.getVALUE() + ")");
}

/* Test for retrieving previous rank */
System.out.println("\nRank before " + myRank1 + ": "
+ myRank1.getPrevious());

/* Test for comparing two cards */
System.out.println("\nCompare value between " + myCard1 + " & "
+ myCard2 + " is " + myCard1.compareTo(myCard2));

/* Test for accessor methods*/
System.out.println("\nGet rank method: " + myCard1.getRank());
System.out.println("Get suit method: " + myCard1.getSuit());

/* Test for toString method */
System.out.println("\ntoString Method: " + myCard1);

/* Test for sum method */
System.out.println(myCard1 + " + " + myCard2 + " = "
+ sum(myCard1, myCard2));

/* Test for isBlackjack method */
System.out.println("isBlackjack method: " +
isBlackjack(myCard1, myCard2));

/*
The following generates a deck of cards to allow for better
testing of the two comparator classes.
*/
List<Card> myDeck = new ArrayList<>();

for (Suit s : Suit.values()) {
for (Rank r : Rank.values()) {
Card newCard = new Card(r, s);

myDeck.add(newCard);
}
}

/* Test for CompareAscending method */
Comparator compAsc = new CompareAscending();
myDeck.sort(compAsc);
System.out.println("\nCompareAscending Sorting: ");
for (Card c : myDeck) {
System.out.println(c);
}

/* Test for CompareSuit method */
Comparator compSuit = new CompareSuit();

myDeck.sort(compSuit);

System.out.println("\nCompareSuit Sorting: ");
for (Card c : myDeck) {
System.out.println(c);
}
}
}
2 changes: 1 addition & 1 deletion src/question2/Dealer.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
***************************************************************************** */
package question2;

import java.util.*;
import java.util.*;

/**
*
Expand Down
Loading

0 comments on commit fe3a81f

Please sign in to comment.