Answered step by step
Verified Expert Solution
Question
1 Approved Answer
5. Add the following method near the bottom of the Card class: public int compareTo(Card other) 6. Before completing this method, there are a
5. Add the following method near the bottom of the Card class: public int compareTo(Card other) 6. Before completing this method, there are a few other helper methods to implement. 7. Create an equals (Card other) method in class Card.java. This method must return true if both the rank and suit are the same between this and other, or false otherwise. 8. Create two private helper methods called getSuitValue() and getRankValue(). Both methods will have int return types. These methods will be used to order the cards given the specified rules and hints below: getSuitValue() returns the value 1 if the suit is "D", the value 2 if the suit is "C", 3 for "H", and 4 for "S". getRankValue() returns the value 2 if the rank is "2", 3 if the rank is "3", ..., 10 if the rank is "10", 11 if the rank is "J", "Q", or "K" and 12 for "A". Hint: Use Integer.parseInt(rank) for the card ranks that are numerical. 9. Go back to the compareTo(Card other) method to fill it in based on the following specifications: Call the equals() method to see if the two cards are the same (return 0 if so). Use the getRankValue() method on both cards and compare them. If they have different rank values, if this.getRankValue() is larger than other.getRankValue() return 1, otherwise return -1. If the cards have the same rank value, proceed to the next option. Use getSuitValue() to compare the two cards of the same rank value and if this.getSuitValue() is larger than other.suitValue() return 1; otherwise return -1. 10. Run TestCards.java to check if your ordering system was implemented correctly. The first example, at the top, should produce the following results: 7 of D 7 of D 7 of H 10 of C K of S A of H 11. The results of the second example are found in Output8.txt.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started