Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this question you will implement classes for a basic card game. You may assume that the enums Rank and Suit exist, as defined in

For this question you will implement classes for a basic card game. You may assume that the enums Rank and Suit exist, as defined in lectures. In addition, the Rank class has the following method: int getPoints() Returns the number of points a given Rank would score.

a) Implement an immutable Card class with the following: (6 marks)

i. Two attributes: a Rank and a Suit.

ii. Appropriate initialization, accessor, and mutator methods.

iii. A compareTo method that results in Card objects being arranged in decreasing order of the number of points given by the Rank; for example, if c1's rank is worth less points than c2's, c1.compareTo(c2) should be negative.

b) Implement a Player class with the following: (14 marks) i. Two attributes: a numeric playerID, and a list of Card objects (the player's hand) ii. Appropriate initialization, accessor, and mutator methods. iii. A method to add a Card to the player's hand. iv. A method to calculate the total score of the player's hand. v. A method to sort the player's hand. vi. A method to play the best Card; the best Card is the one with the highest score. The Card played should be returned, and removed from the player's hand as a result.

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions