Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
Java Collections Lab part 1 
 
In the next two labs, you will be helping to build a card game program. The program 
allows the user to play the Ghanaian card game Spa against three other opponents. Most 
of the code has already been written for you, but you have to complete some very 
important parts before it will work. 
 
These two labs will be assessed as part of your final project and will be worth 10% of 
your grade.  
 
The complete and running spa game is due on Wednesday 21st July at 5.00 pm. 
 
1. Look at the class CardSuit.java in the spa.card package.  A comment in the 
class says that there are exactly four instances of CardSuit. Why can't more instances 
of CardSuit be created? Why doesn't this class need to override the equals method? 
How would another class refer to the Diamonds suit?  
 
2. Change CardSuit so that it implements the Comparable interface.  The 
comparison of card suits should follow this ranking: spades >  diamonds > hearts > clubs. 
Compile CardSuit.java. 
 
3. Correctly implement the equals and compareTo methods in Card.java.  Read 
the comment above the compareTo method to see how the cards should be compared. 
 
4. Add a field to Deck.java to store all the cards in the Deck. We want to be able to 
draw cards from the Deck, sort the deck, and shuffle the deck. What should the type of 
the field be and why? 
 
5. Correct implement the Deck constructor. Hint: do not write 52 lines, each of which 
creates and adds a different card; instead, use the two public arrays declared by Card to 
accomplish this with less code. 
 
6. Correctly implement every other method in Deck except for hashCode. Hint: you 
can write the sort and shuffle methods in one line if you know where to look.