So I have to code a HiLo card game program in java and here are the instructions on how it works:
there are two classes Card and Deck
The Card Class contains 2 private variables int suit and int faceValue A Constructor which takes the 2 variables as parameters like this: + Card(int suit, int faceValue) Getters --> getSuit:int and getFaceValue:int A compareTo(Card card):int method A toString():String method
The Deck Class contains a private random variable of Random type private random : Random A no parameter constructor Deck() A deal method that takes no parameter and of Card type
The Card class has a suit which is a digit from 0 to 3 that represents the suit of a card: - 0 represents Spades (which is the highest ranked suit) - 1 represents Hearts (the second highest suit) - 2 represents Diamonds (the third highest suit) - 3 represents Clubs (the weakest suit)
The faceValue is a value between 1 and 13; 1 represents Ace, 11 is Jack, 12 is Queen and 13 is King.
The compareTo method compares the current instance (i.e., this) with the parameter card. If the two objects have the same suit and faceValue, the method returns 0. If the current instance is higher (higher value, or if they are the same value, higher suit), then the method returns a positive value (it can be +1 or any other positive value since the magnitude is not important, only the sign). If the current instance is lower, return a negative value.
The toString method returns a String representation of the card (e.g., “Ace of Spades”, “2 of Hearts”)
The Deck class has an instance of type Random which it uses when instantiating and dealing a new Card.
Now code an application class called HiLoApp which will: - instantiate a Deck object - deal and display the first card - ask the user to choose -1 if they think the next card will be lower, +1 if the next card will be higher, or 0 to quit the game o deal and display the next card o display whether the user chose correctly o count the number of attempts and correct guesses
The main method is to continuously carry out these steps until the user enters 0 to quit the game. At this point, display the total number of attempts and correct guesses made by the user.
So far I coded this for the Card class:
public class Card
{
private int suit;
private int faceValue;
//Constructor
public Card(int suit, int faceValue)
{
this.suit = suits;
this.faceValue = faceValue;
}
public int getSuit()
{
return suit;
}
public int getFaceValue()
{
return faceValue;
}
public int compareTo(Card card)
{
}
public String toString
{
String cardName = null;
switch (faceValue)
{
case 2:
cardName = "Two";
break;
case 3:
cardName = "Three";
break;
case 4:
cardName = "Four";
break;
case 5:
cardName = "Five";
break;
case 6:
cardName = "Six";
break;
case 7:
cardName = "Seven";
break;
case 8:
cardName = "Eight";
break;
case 9:
cardName = "Nine";
break;
case 10:
cardName = "Ten";
break;
case 1:
cardName = "Ace";
break;
case 11:
cardName = "Jack";
break;
case 12:
cardName = "Queen";
break;
case 13:
cardName = "King";
break;
}
switch (suit)
{
case 0:
cardName += "Of Spades";
break;
case 1:
cardName += "Of Hearts";
break;
case 2:
cardName += "Of Diamonds";
break;
case 3:
cardName += "Of Clubs";
break;
}
return cardName;
}
How can I get the program to deal the cards and how is it supposed to know the card number limit which is 52 and how does it know the suit 0 which represents Spades is the highest ranked and so forth
Aucun commentaire:
Enregistrer un commentaire