(Solved): CSE205 Assignment 2...
CSE205 Assignment 2
Cards & Deck – 50pts
• Loops and Conditionals
The goal of this assignment is to create a re-usable Card and Deck class. This assignment will lead into Assignment 3 where you will build more classes to flesh out a card game.
Use the following Guidelines:
• Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc).
• Keep identifiers to a reasonably short length.
• User upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for all other identifiers (variables, methods, objects).
• Use tabs or spaces to indent code within blocks (code surrounded by braces). This includes classes, methods, and code associated with ifs, switches and loops. Be consistent with the number of spaces or tabs that you use to indent.
• Use white space to make your program more readable.
All files in submitted assignments must begin with the descriptive comment block. To avoid losing trivial points, make sure this comment header is included in every assignment you submit, and that it is updated accordingly from assignment to assignment.
Your header should identify you as the author and have a short description of the class contained in the file and what it does in your software.
You are eventually going to create a multi-class system to play a card game. For this assignment you will lay the groundwork by creating the Card and Deck classes and demonstrating them working.
• Card – Standard 52-Card Deck cards
• Deck – Deck of cards with deck behaviors
• Assn2 Class (Main) – Demonstrates the cards and deck functionality
Part 1 – Build your Card Class
Start by building your basic Card Class
? Card(value:int, suit:char)
o Getters for value and suit
? You can’t change a card after its built, so no setters
o Getter/Setter for FaceUp
? You can flip it over
? Override it to print your card nicely
Part 2 – Build your Deck Class
? Keeps track of the number of valid cards in the array
? Helps initialize the array
• Default – fill with standard deck of 52
o Hint make a private method to help you fill it
• Set the maxSize to value passed in
• Initialize array … but don’t fill it
• Use this constructor to make an empty deck to fill via the Add() method
? Shuffle the array
• Hint: remember Card object references
• Hint: Do the names Fisher and Yates ring a bell? Google might know …
? Reduce the card count, return a Card object reference
• Hint: last card in the array is easiest
• Hint2: think about setting the Card reference in the array to null – not necessary, but cleaner
o AddToTop(newCard:Card )
? Take a Card reference add it to the array at index last valid index if able to
? Take a Card reference add it to the array at the 0 index if able to
? Method to output your array all nice like …
? Hint: card.toString()