Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The aim is to make sequences of cards in a 32-card deck in object programming with Java and the associated UML diagram. I have to

The aim is to make sequences of cards in a 32-card deck in object programming with Java and the associated UML diagram. I have to create sequences of cards and sort them (assuming that the sequences do not contain duplicate cards).

The steps are as follows: 1. Model the Color class with clubs, diamonds, hearts, and spades possible. 2. Model the Value class with ace, two, three, four, five, six, seven, eight, nine, ten, jack, queen and king possible. 3. Model the Card class with a color and a value. 4. Define an equality, equals, for the colors. 5. Define a comparison, compareTo, for the values that will return -1, 0, 1 depending on the value of the comparison (<, == and > respectively). 6. Model the Hand class using the composite pattern, a hand represents a sequence of cards in the order they were dealt. The two subclasses will be named : WithoutCard and WithCard

7. The abstract operations for Hand are: - size: Hand -> int: calculates the total number of cards. - insert: Hand Card -> Hand: inserts a card into a sorted hand in ascending order of the values. - sort : Hand -> Hand : sorts the hand in ascending order of values. - isSorted : Hand -> boolean : test if the sequence is in ascending order of values.

Some guidelines to help you write the methods.

For the methods equals, compareTo you can redefine the existing methods in Object but it is not necessary. For comparison a simple solution is to assign an integer to each value.

For sorting you have to use the insert method to recursively sort by insertion.

For the isSorted method think about the different length cases of the hand. You need to access the second element of a hand h, if it is known to exist.

Write and run tests based on the following properties: h.isSorted() AND h.insert(c).isSorted() must be true regardless of the card c and the hand h.

h.sort().isSorted() must be true whatever the hand h is.

Urgent need for UML diagram and java code thank you very much

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David M. Kroenke

12th Edition International Edition

1292023422, 978-1292023427

More Books

Students also viewed these Databases questions

Question

3. Existing organizations and programs constrain behavior.

Answered: 1 week ago