Workshop Week 4 Objectives.

Added on - 16 Sep 2019

Trusted by 2+ million users,
1000+ happy students everyday
Showing pages 1 to 3 of 8 pages
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 thedesign.A deck of cards has 52 cards made up of 4 suits (Hearts, Diamonds, Clubs, Spades) and13 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 thevalue of the rank and a toString() method that returns the suit value and rank value as aString.Deck has a LinkedList of Card objects, a display() method to display all card objects, arandom() method to A index into the list and get a random card and a draw() method thatreturns a random Card.10 minute exerciseName:Student Number:DeckCardSuit [enum]Rank [enum]
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 andthe value for each using a complex enum ie Two(2) etc.The Deck has a LinkedList of Card objects, populate the cards LinkedList in theconstructor 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 andrank of each card.Write the method called random() that returns a random number between 0 & 51 (use thesize 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 dealtfor 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 thetotal value of all the cards in the hand and a String toString() method which iteratesthrough the list of cards, adding the suit and rank of each card (calling toString() on eachCard object) and the total value of the hand.Create a new class called TestDeck, which creates a Deck object, a Hand object, drawstwo random cards from the deck and adds them to the hand, displays the suit and rank ofthe 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
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){ = id; = name;this.period = period;}public boolean matches(int id){return == id;}public void rent(Customer customer){ //set video status to rentedSystem.out.print("\tVideo rented: " + name);status = Status.RENTED;renter = customer;}public void videoReturn(){ //set video status to not rentedSystem.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:
Desklib Logo
You are reading a preview
Upload your documents to download or

Become a Desklib member to get access