i can not seem to get my code to compile.
any help would be greatly appreciated.
it will not find my displayValue method although it is clearly defined in my Card class...
Card ClassCODE
public class Card {
private int value;
public int Card(int setValue) {
value = setValue;
return value;
}
void displayValue() {
for (int i = 1; i <= 5; i++) {
int card = (int) (Math.random() * 13) + 2;
if (card == 11)
System.out.print("Jack ");
else if (card == 12)
System.out.print("Queen ");
else if (card == 13)
System.out.print("King ");
else if (card == 14)
System.out.print("Ace ");
else
System.out.print(value);
}
}
}
Poker ClassCODE
/*
1. (20 pts) Write a template class called Card in a separate file. It should have one instance variable for the
value of the card. The constructor receives no parameters and sets the value to a random number from 2 to
14 using Math.random(). Include a method called displayValue() that prints the value of the card using the ,
ÒJackÓ for 11, ÒQueenÓ for 12, ÒKingÓ for 13, and ÒAceÓ for 14. The method receives no parameters and
does not return anything. Hint: see the solution to homework #3.
2. (50 pts) In a separate file, write an application class called Poker that creates an array of five Cards using the
template class from problem #1. Display all of the card values as well as the highest card value. The
application class should always use the displayValue() method to print card values, but just print the number
for the highest card. The following is an example of how your output might look:
3. (30 pts) In a separate file, write an application class called Poker2 that is just like the Poker class from
problem #2 except that it displays the highest card by using the actual element in the array that has the
highest value. The following is an example of how your output might look:
*/
public class Poker {
public static void main (String args[]) {
int highest = 0;
System.out.print("Your cards are: ");
Card[] theCards;
theCards = new Card[5]; // Creates an array of 5 cards
for (int i = 1; i < 5; i++){
theCards[i] = new Card();
theCards[i] = theCards.displayValue();
if (theCards[i] > highest)
highest = theCards[i];
}
}
}