You are on page 1of 6

The assignment is due in Blackboard at 6am, Wednesday 3/21

CSE1341 - Lab 6 Assignment

Part 1: (70 points)


Build a Java program with three classes, according the UML Class Diagram below.

Be sure to follow the eight steps you were taught in class, and create getters, setters, constructors, and a toString() method. Create a main method (only) in the CardTester class with the following instructions: Deck d = new Deck(); System.out.println(d); d.shuffle(); System.out.println(d);

Your shuffle method should go through the deck and have each card swap places with another card selected by Random Number (as you did in your previous lab assignment.) Sample output below (of course, your shuffled output will vary): UNSHUFFLED OUTPUT: SHUFFLED OUTPUT:

Tips The constructor for Deck will create all 52 instances of Card and add them to its array named allCards. When creating the Card instances, create four for loops one for each suit. The face value of the cards should be 2 14. (11-14 represent Jack, Queen, King and Ace.) The toString method in Deck should create one large String containing the toString values of all 52 cards, with a \n inserted between each of them. The constructor for Card is called from within the constructor of Deck, which passes an int and a String for each Card (representing faceValue and suit.) the toString method in Card should display faceValue of suit for each Card instance. The cards with faceValue of 11-14 should display Jack, Queen, King, or Ace instead of the integer.

Part 2: (30 points)


Add a class named Hand to your system based on the model below. The Deck should create the Hand it the constructor of Deck. You will shuffle the Deck and construct the Hand using the top six cards from the shuffled deck. Hand will retain the array of six cards in its myCards attribute. When CardTester asks the Deck to computeScore, it in turn asks its Hand to computeScore, returning the score all the way back to CardTester. The scoring is based on the total pairs in the hand based on the note in the model below. You should add/change the classes, attributes and methods that are highlighted in the model below:

Be sure to follow the eight steps you were taught in class, and create getters, setters, constructors, and a toString() method in the Hand class.

Comment out the code shown below in the main method in your CardTester class and add the code shown below the commented code: Deck d = new Deck(); /* COMMENT OUT CODE FOR TESTING PART 1 System.out.println(d); d.shuffle(); System.out.println(d); */ int y = d.computeScore(); System.out.println(Score is + y); SAMPLE OUTPUT:

HINTS: To copy the contents of the array passed into the Hand constructor, you could use System.arraycopy (see the lecture notes about arrays) or write a loop to copy the six cards from one array to the other, one at a time. From within the class Hand, you cannot get the suit or faceValue of a card directlyyou must use the getSuit() and getFaceValue() methods. Remember that you must use the equals method to compare two String instances. == wont work. When constructing the toString method in Hand, dont duplicate the toString code in Card just call the Cards toString method to get its String representation.

NOTES: Each program should include comments that explain what each block of code is doing. Additionally, the programs should compile without errors, and run with the results described in the exercise. The following deductions will be made from each exercise if any of the following is incorrect or missing: Proper formatting [5 points] Proper names for classes and variables [5 points] Comments [5 point] Program doesn't compile [ 10 points] Source code (java file) missing [ 10 points] Executable (class file) missing [10 points] Missing loop where a loop was required [5 points]

The assignment is due in Blackboard at 6am, Wednesday 3/21.

You might also like