Starting from:

$30

Object Oriented Design and Programming Assignment 1


CSIT121
Object Oriented Design and Programming
Assignment 1
Objectives:
Practice java programming with classes and objects, constructors, copy
constructors, enum type, array, ArrayList (generic version), overloaded
methods, passing by reference and etc.

Task 1: (6 marks)
The following shows a deck of 52 playing cards:
- Four suits (Spade, Heart, Diamond and Club (in that order). We usually use
characters ‘S’, ‘H’, ‘D’ and ‘C’ to denote the 4 suits. 
2
- Rank values from Two, Three ……Ten, Jack, King, Queen and Ace (in that
order). We usually use characters ‘2’, ‘3’, ‘4’, … , ‘9’, ‘T’, ‘J’,
‘Q’, ‘K’, ‘A’ to denote the rank values.
The following UML diagram shows the objective of this assignment:
Let us know explore each of the tasks you need to design for this assignment:
Task 1
Define two enum types, one for Suit whose constants (Spade, Heart,
Diamond and Club) take one character parameter (the values as quoted
above, ‘S’, ‘H’ etc); and one for Rank whose constants (Two, Three etc)
take one character parameter (the values as quoted above, ‘2’, ‘3’ etc). 
3

Task 2
Suggest and implement a class called PlayingCard according to the
following UML diagram:
It is a very simple class with constructors, accessor methods, mutator
method and a toString method (its format can be seen in the screen
captured images). 
4
Task 3
The following UML shows what you have to do in the main method:
Task 3a
The duty of the main method is simple. You construct an ArrayList of
52 (MAXD) playing cards by calling the method deckOfCards to achieve
the target; and display them (by calling the printDeck method to do this
task). Note that each set of playing card has 13 (MAXC) of spades, hearts,
diamonds and clubs. When the two methods are called in the main method,
you will see the following display:
Task 3b
The next duty of this assignment is to transfer all the objects stored in the
ArrayList (i.e. the list constructed in the Task 3b) playing cards to an 
5
array of playing cards (invoke listToArray method). During the transfer,
you need to have new objects to be stored in the array i.e. using the copy
constructor of PlayingCard; and print this array (by calling the
printDeck method to do this task). Note that you have two overloaded
printDeck method. When the two methods are called in main, you will
get the following display:
Task 3c
In this task, you construct an array of String objects by calling the
transfer method. This method actually stores all the objects constructed
in Task 3b
You are required to shuffle (the shuffle method) the array. You are not
allowed to use the shuffle method defined in the Arrays class. What
you will do in the shuffle method is to generate a positive integer k
(reasonable value); and you need to shuffle the cards k times. To do this,
you generate two integers i and j, and swap the playing card i and the
playing card j.
In the above UML diagram, you see the two methods:
- The swap method swaps the i
th and the j
th string objects
- The displayStringArray method displays the String objects
according to the above display.
When the shuffle method and the printDeck method are called, you
will get the following display: 
6

 Information will be stored in a 2D array in Task 3d
Task 3d
In the above screens captured, objects are printed by calling the toString
method (implicitly) to print out the objects.
You then define a 2D array with 4 rows and 13 columns storing the
randomly shuffled array (as shown in the above screen)
For each row (considered to be a hand), you sort them. Note that you should
use the sort method in Arrays class. The following shows a picture of a hand:
In each hand, you count the number of spades, hearts, diamonds and clubs
and display the distribution. In the above hand, you have 4 spades, 2 hearts,
4 diamonds and 3 clubs. 
7
Explore passing by reference by using the following class:
by getting the hand info (or distribution) i.e. the method getHandInfo as
shown in the UML diagram
IMPORTANT
Put all your classes in a file called YourName_A1.java and make sure
that this file can be compiled and can be executed. Upload ONLY this file
to Moodle. ALL ZIP FILE SUBMISSION WILL BE REJECTED
No re-submission will be allowed after grading.
In the above file, remember to put down your name and also the following
declaration (some similar contents):
// Tell me if it is your own work, and whether you have passed your
// program to your friends etc etc etc
// and willing to accept whatever penalty given to you.
- Wrong file name -0.5 mark
- No declaration, no name etc -0.5 mark 
8
- Failing to demo -1 mark
- Programs indentations and alignment of statements -0.5 mark
- Late penalty: -0.1 mark per hour 

More products