Ask a question from expert

Ask now

Using enum and LinkedList structures for Decklib

8 Pages2037 Words334 Views
   

Added on  2019-09-16

About This Document

This workshop covers the use of enum and LinkedList structures for creating a deck of cards in Decklib. It includes tasks such as designing a deck of cards, evaluating and implementing the deck, reading code, identifying inheritance, and testing inheritance. The workshop also covers creating a video store using LinkedLists, group classes, list lookup pattern, and enums.

Using enum and LinkedList structures for Decklib

   Added on 2019-09-16

BookmarkShareRelated Documents
IAPP001 Applications ProgrammingWorkshop Week 4ObjectivesUse enum and LinkedList structuresTask 1 – Complex enum DemonstrationYour tutor will demonstrate how to create the complex enum Rank.10 minute exerciseTask 2 – Designing a deck of cardsYour tutor will distribute to each group a deck of cards; use the deck to brainstorm the design.A deck of cards has 52 cards made up of 4 suits (Hearts, Diamonds, Clubs, Spades) and 13 ranks (Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King, Ace) for each suit. The ranks have values 2,3,4,5,6,7,8,9,10,10,10 & 10 respectively.A Card has a suit and a rank (passed into the constructor), a getValue() that returns the value of the rank and a toString() method that returns the suit value and rank value as a String.Deck has a LinkedList of Card objects, a display() method to display all card objects, a random() method to A index into the list and get a random card and a draw() method that returns a random Card.10 minute exerciseName:Student Number:DeckCardSuit [enum]Rank [enum]
Using enum and LinkedList structures for Decklib_1
IAPP001 Applications ProgrammingTask 3 – Evaluate and implement the deckCreate a Suit class (select Enum radio button in class type) and enter the suit types.Create a Rank class (select Enum radio button in class type) and enter the rank types and the value for each using a complex enum ie Two(2) etc.The Deck has a LinkedList of Card objects, populate the cards LinkedList in the constructor using nested enhanced for loops. The cards list should hold 52 card objects.Write the display() method that iterates through the cards list and displays the suit and rank of each card.Write the method called random() that returns a random number between 0 & 51 (use the size of the cards list not a constant).Now write the draw() method that returns a random Card from the list (call the random() method and index into the list to get the Card).Create a Hand class that has an attribute LinkedList<Card> cards (to hold the cards dealt for a hand), a method void add(Card card) to add a card to the hand, a method int size() which returns the number of cards in the hand, a method int value() which calculates the total value of all the cards in the hand and a String toString() method which iterates through the list of cards, adding the suit and rank of each card (calling toString() on each Card object) and the total value of the hand.Create a new class called TestDeck, which creates a Deck object, a Hand object, draws two random cards from the deck and adds them to the hand, displays the suit and rank of the cards in the hand and the value of the hand – just write the code in the constructor.Ask your tutor if you need help.40 minute exerciseName:Student Number:[][]DeckCardHandTestDeckCardRankSuitRankSuit
Using enum and LinkedList structures for Decklib_2
IAPP001 Applications ProgrammingTask 4 – Reading CodeAs a group of 2-4 students, build the class diagram for each of the following classes: public class Video { private final double PRICE = 5.0; private int id; private String name; private int period; private Customer renter; private Status status; public Video(int id, String name, int period) { this.id = id; this.name = name; this.period = period; } public boolean matches(int id) { return this.id == id; } public void rent(Customer customer) { //set video status to rented System.out.print("\tVideo rented: " + name); status = Status.RENTED; renter = customer; } public void videoReturn() { //set video status to not rented System.out.println("Video id:"); status = Status.FOR_RENT; renter = null; } public double getPrice() { return PRICE; } public String getName() { return name; } public boolean isOut() { return status == Status.RENTED; }Name:Student Number:
Using enum and LinkedList structures for Decklib_3

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
Java program to simulate customer queues in a grocery store
|2
|601
|291

Bus Stop Display System Development
|9
|1084
|225

Using Graphical Objects in Java: Splat Program Example
|5
|1704
|173

OO Design and Polymorphism Design: Assignment
|16
|2346
|292