QuestionQuestion

1.   The Card class

Requirements: You are to write a class called Card – this will represent a playing card. Card should have the following:

Data:
• Its data are the “rank” and “suit.” The rank should be an int that is in the range 2-14 (2=2, 3=3, … , 10=10, 11=Jack, 12=Queen, 13=King, 14=Ace).   The suit should be a char that is either an ‘S’, ‘H’, ‘D’, ‘C’, ‘s’, ‘h’, ‘d’, ‘c’ (‘S’=Spade, ‘H’=Heart, ‘D’=Diamond, ‘C’=Club in upper or lower case).

Constructors:
• A default constructor that will set the values to the Ace of Spades.

• A parameterized constructor that will receive a rank and a suit, in that order. If either the rank or the suit is out of range, then:
         throw new IllegalArgumentException(“your descriptive String here”);

• A copy constructor that will receive a Card and initializes the data (of the new instance being created) to be the same as the Card that was received.   

Methods:
• A toString() method that returns a String representing the Card. The String it returns can just concatenate the rank and the suit (but it should change a rank of 1 or the ranks > 10 to what they mean).   A rank of 11 would be a “J” that would then be concatenated to the suit). So a Card with rank of 13, suit of ‘S’ would return “KS” in its toString(). If you want to show it, you could return it as “K\u0006”.   Character #3 is actually a picture of a heart, character #4 is a diamond, character #5 is a club, and character #6 is a spade. They will print if you output to the DOS window (so do not “Capture Output”).

• An equals method that returns true if what was received is equal to the current instance. Be sure that it follows the logic for .equals exactly.

• A compareTo method that receives another Card and returns a positive integer if the current instance is > the Card that was received, returns a negative integer if the current instance is < the card that is received, and 0 if they are equal. A Card that has a higher rank is greater than a Card with a lower rank.   So 7H < 10D, 14H > 10C, 13D == 13S, etc.

Testing: Since your Card class will not have a main method, it cannot run (nor is it designed to run by itself). Instead you must have some sort of “driver” program that uses it by creating new instances of Cards and then telling them to call their methods.   For testing, you can compile and run the CardTester class that is provided. Be sure it is in the same package (directory if using Textpad).

2.   The Point class

Requirements: You are to write a class called Point – this will represent a geometric point in a Cartesian plane. Point should have the following:

Data:
• that hold the x-value and the y-value. They should be ints and must be private.

Constructors:
• A default constructor that will set the values to (0, 0)

• A parameterized constructor that will receive 2 ints (x then y) and set the data to what is received.

• A copy constructor that will receive a Point and initializes the data (of the new instance being created) to be the same as the Point that was received.

Methods:
• A toString() method that returns a String representing the Point. It should be in the form (x, y). with a single space after the comma

• A method called distanceTo(Point other) that returns the distance (as a double) to the other Point that is received.

• A method called halfwayTo(Point other) that returns a new Point that is halfway between itself and the other Point that is received.

• A method called translate(int xmove, int ymove) that will return nothing and “translates,” or shifts, the data by the distances passed in. So if a Point has data x=3 and y=5, translate(5,2) will cause it to change its data to x=8 and y=7.

• A method called equals(Object otherObj) which returns true if it is equal to the otherObj. Be sure that it follows the logic for .equals exactly.

Testing:   You may test your Point class by using my PointTester as the “driver.”

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

public class Card {
    private int rank;
    private int suit;
   
    private final char[] suits = {'H', 'h', 'S', 's', 'D', 'd', 'C', 'c'};
    private final String[ ] ranks = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"};
   
    /**
    * default constructor
    */
    public Card() {
       rank = 14;
       suit = 6;
    }

    /**
    * constructor
    * @param rank
    * @param suit
    */
    public Card(int rank, char suit) {
      
       if (rank < 2 || rank > 14) {
            throw new IllegalArgumentException("your descriptive String here");
       }
       boolean exist = false;
       for (int i = 0; i < suits.length; i++) {
            if (suit == suits[i]) {
                this.suit = i;
                exist = true;
                break;
            }            
       }...

50% discount

Hours
Minutes
Seconds
$25.00 $12.50
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats