Question
Asked by:
JMG
JMG
Rating : No Rating
Questions Asked: 1
Tutorials Posted: 0
 

$1.50 The programThis week you are going to

Q:
The program
This week you are going to write three classes: Card.java, Deck.java and DeckTester.java. The specification for each class is given below.

Card.java
This is a simple class that represents a playing card.




Card has two attributes:
• rank which is a String that represents the value of a card. It takes a value in the range: “ACE,”2”,”3”,…,”JACK”,”QUEEN”,”KING”; and
• suit which is a String which takes a value in the range: “SPADES”,”DIAMONDS”,”CLUBS”,”HEARTS”.

The class has a single constructor which takes two parameters: the first is an int that represents the rank in the range 1 to 13; the second a String representing the suit. The constructor must convert the int into an appropriate String value – 1 should be converted to , 2 TO … 13 TO ..

Additionally there are two accessor methods (getSuit & getRank) that return String representations of the suit and rank respectively.

A skeleton of the class is provided. You have to complete the missing components. This file can be found on Blackboard with the homework specification.

Deck.java
This class represents a deck of 52 playing cards.



This class has two attributes: an array of type Card holding the 52 cards of the deck and an int that holds the number of cards in the deck, (this attribute is not used in this homework but may be used later);

A skeleton of the class is also provided. You have to complete the missing components. This file can be found on Blackboard with the homework specification.

DeckTester.java
This class contains the main method. Its purpose is to allow you to demonstrate that your Deck class works as anticipated. In particular you need to:
• Create an instance of the Deck class;
• Confirm that the constructor works correctly;
• Confirm that shuffle works correctly.
 


   
   
   
   
 
Available Tutorials to this Question
Posted by:
jannwith3
jannwith3
Rating (355): A-
Questions Asked: 182
Tutorials Posted: 950, earned $3,165.12
 

$2.50 here is your answer.

  • This tutorial hasn't been purchased yet.
  • Posted on Feb 25, 2009 at 12:07:56PM
A:
Preview: ... ts of class Card<br>84. * Each card has a rank and a suit. No checks are made for invalid values<br>85. * @param rank an int representing the valus of the card, range 1..13<br>86. * @param suit a String representing the suit of card: values <br>87. "SPADES","DIAMONDS","CLUBS","HEARTS"<br>88. */<br>89. public Card(int rank, String suits)<br>90. { <br>91. this.suit = suits;<br>92. <br>93. <br>94. // must convert the integer value of rank to an appropriate String<br>95. if (rank == 1)<br>96. {<br>97. this.rank = "Ace";<br>98. }<br>99. else if (rank == 11)<br>100. {<br>101. this.rank = "Jack";<br>102. }<br>103. else if (rank == 12)<br>104. {<br>105. this.rank = "Queen";<br>106. }<br>107. ...

The full tutorial is about 1180 words long plus attachments.

Attachments:
Rigcomputer science.docx (14K) (Preview)
Posted by:
rainman
rainman
Rating (40): A+
Questions Asked: 2
Tutorials Posted: 174, earned $906.64
 

$15.00 Java Card Game. All 3 Files And Classes As Specified. Compiles, Commented For Your Learning Benefit, Works.

  • This tutorial hasn't been purchased yet.
  • Posted on Feb 25, 2009 at 12:31:02PM
A:
Preview: ... d object at in the array<br> //s * 13 because there are 13 cards per suit<br> //+ r for rank offset<br> deck[s * 13 + r] = new Card(ranks[r], suits[s]);<br> }<br> }<br> <br> }<br><br> //shuffles the deck of cards.<br> public void shuffle()<br> {<br> //loop through each card in the deck and swap it with some random card.<br> for (int i = 0; i < 52; i++)<br> ...

The full tutorial is about 750 words long plus attachments.

Attachments:
DeckTester.java (0K) (Preview)
Card.java (0K) (Preview)
Deck.java (2K) (Preview)
preview.JPG (43K) (Preview)
   
Join Now or Log In
Get Tutoring
Get Paid
Academic Honesty