This project requires the use of the following Java program files:
|
Download them to your PC before doing this project.
Abide to the Emory Honor code when doing assignments.
This assignment requires you to implement:
|
You find the getRank( ) and Card(Card c) methods in the Card.java program file:
public class Card { private static String[] suitToString = {"Spades", "Hearts", "Diamonds", "Clubs"}; private static String[] rankToString = {"Ace", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King" }; private int suit; // Suit of this Card private int rank; // Rank of this Card ..... // ****************************************************************** // Part 2 // crad(Card c): copy constructor, create a copy of Card c // ****************************************************************** public Card(Card c) { // Write your code here } // getSuit(): returns the string representation of the suit of this card public String getSuit() // Return the suit of card as String { return suitToString[suit]; } // ****************************************************************** // Part 1 // getRank(): returns the string representation of the rank of this card // ****************************************************************** public String getRank() // Return the suit of card as String { return ""; // Make changes } .... } |
You find the DeckOfCards(DeckOfCards d) method in the DeckOfCards.java program file:
public class DeckOfCards
{
private Card[] deck;
private int dealPosition;
....
// Constructor to make a EXACT COPY of this deck of cards
DeckOfCards(DeckOfCards d)
{
// Write your code here
}
....
}
|
Warning:
|
Write the method String getRank() method in the Card class, which returns the rank of the Card as a String.
Use the provided Java program class file
Card.java
to write the
getRank() method.
Use the provided Java program file
TestA.java
to test the
getRank() method.
For example, consider the following statement, which instantiate 2 Card objects:
Card a = new Card("Clubs", "Ace"); Card b = new Card("Spades", "King"); |
Sample calls to getRank() are shown below:
Call Return value Reason =========================================================================== a.getRank() "Ace" a is a Ace of Clubs b.getRank() "King" b is the King of Spades |
Write the copy constructor Card(Card c), which initialize a new Card object using the input Card c
The new Card object must have the same suit and rank as the input Card c
Furthermore, when you modify one of the Card object, the other Card object must not be modified (if this fails, you made an alias and not a copy)
Use the provided Java program file
Card.java
to write the
Card(Card c)
constructor method.
Use the provided Java program file
TestB.java
to test the
Card(Card c)
constructor method.
The test program will print the message:
Copy test failed: a.getSuit() != b.getSuit() |
if the copy constructor did not copy the content of the input card correctly.
The test program will print the message:
System.out.println("Alias test failed: a.getSuit() == b.getSuit() |
if the copy constructor made an alias instead of a real copy.
Write the copy constructor DeckOfCards(DeckOfCards d), which initialize a new DeckOfCards object using the input DeckOfCards d
The new DeckOfCards object must have the same 52 cords in the same order as the input deck d
In addition, the new DeckOfCards object must have the same number of undealt cards
Furthermore, when you shuffle one of the DeckOfCards object, the other DeckOfCards object must not be shuffled (if this fails, you made an alias and not a copy)
Use the provided Java program file
DeckOfCards.java
to write the
DeckOfCards(DeckOfCards d)
constructor method.
Use the provided Java program file
TestC.java
to test the
DeckOfCards(DeckOfCards d)
constructor method.
The test program will print the message:
Copy test failed: a.getSuit() != b.getSuit() |
if the copy constructor did not copy the content of the input card correctly.
The test program will print the message:
System.out.println("Alias test failed: a.getSuit() == b.getSuit() |
if the copy constructor made an alias instead of a real copy.
You must be on Emory campus (e.g.: Emory unplugged) in order to turn in an assignment
Use your web browser and visit the cs171 turnin website: click here
Turn in Card.java using assignment code hw2-a
Turn in DeckOfCards.java using assignment code hw2-b
Follow the instructions given from homework 1 to turn in.
You must be on Emory campus (e.g.: Emory unplugged) in order to turn in an assignment
Use your web browser and visit the cs171 turnin website: click here
Use assignment code hw2 to request extension for this homework.
Follow the instructions given from homework 1 to request extension.