Advanced Programming - CS239
LAB 17: Array Lists and other Structures
NOTE: It is not
necessary to build your ArrayList to a particular size. The ArrayList
methods keep the size to the specific number of elements in the list,
regardless of what you use as a starting number.
Getting Ready: Before going any further you should:
Submission – Print this
worksheet and your Hand.java and Driver.java programs. Turn in all pieces. You do not need to submit your actual code.
Part I: This part of the lab will help you understand how a derived
class can implement an interface that the base class does not. REVIEW
1.
1. Compile and execute Driver. What is output? (Copy your output here)
«Ï ----jGRASP exec: java Driver |
2. Explain (in a few sentences) the algorithm used in the compareTo() method in the
PlayingCard class.
The suits are ordered as are the rank (value) and points are awarded
based on suit and rank. The points
are retrieved for both cards based on their ranks (values) . If the points are different, either 1 or
-1 is returned (based on whether this.card’s rank points are greater than or
less than other.card’s rank points.
If the points are the same, the points are retrieved for both cards
based on their suits. These can not
be the same (since their ranks were) and there are no duplicate cards in the
deck. The value returned is again
either 1 or -1 based on whether this.card’s suit points are greater than or
less than other.card’s suit points. |
Part
II: This part of the lab will introduce you to the ArrayList
class.
i. Deal
(from the deck) 5 cards.
ii. Display
the hand.
iii. Remove
a specified card.
iv. Deal
a new card to replace it.
Here are some reminders about coding
style:
§ Separate
declarations and instantiations
§ Remove unused code
§ Don't do more work
than necessary
§ Print headers
§ Only have 1 return
statement per method unless the method is recursive.
Produce
output to show your code works (i.e. test it)
ÏÏ |
Don’t forget to print your code and attach it to this
document.