Lower value meaning when both player have tie in the games for this program p ca
ID: 642335 • Letter: L
Question
Lower value meaning when both player have tie in the games for this program p card have 2 mthod peaccard() and peadeck.
PeacCard derived from card and will override the winner but reuse all the function from card
Peacdeck derive from deck the new class providing a constructor of superclass of array Card with the instance of peaccard. all deck function are reuse.
this was this code look like so far but with error:
//the games of c and some enum
//C
private Suit suit;
private Card face;
public Card(Suit aSuit, Card aFace)
{
suit = aSuit;
face = aFace;
}
// toString method
public String toString()
{
return face + " of " + suit;
}
?
public boolean winner(Card c) {
// TODO: complete this method definition
// winner method return the winner of two cards
if(face.compareTo(c.face) > 0)
return true;
else if(face.compareTo(c.face) == 0 && suit.compareTo(c.suit) >= 0)
return true;
else
return false;
}
}
// the second d class
public class Deck {
private Random random;
private final int NUMBER_OF_CARDS = 52;
private Card[] cards;
private Suit[] suits;
private Card[] faces;
private int index;
public Deck()
{
suits = Suit.values();
faces = Value.values();
index = 0;
cards = new Card[NUMBER_OF_CARDS];
for(CardSuit s : suits)
{
for(CardValue f: faces)
{
cards[index] = new Card(s, f);
index++;
}
}
random = new Random();
}
public Card draw()
{
int s = random.nextInt(suits.length);
int f = random.nextInt(faces.length);
Card card = new Card(suits[s], faces[f]);
return card;
}
}
////////////////////
//peac determine the low value of card
private Suit suit;
private Value face;
public PeaceCard(Suit aSuit, Value aFace)
{
//suit = aSuit;
//face = aFace;
super (aSuit, aFace);
boolean winner(PeaceCard c) {
if(face.compareTo(c.face) > 0)
return;
else if(face.compareTo(c.face) == 0 && suit.compareTo(c.suit) >= 0)
return;
else
return;
}
}
}
// the deck peac
public class PeaceDeck extends Deck {
PeaceCard[][] deckOfCard= new PeaceCard[14][5];//1~13,1~4
public PeaceDeck() {
for(int i=1;i<14;i++)//initial a deck of card
for(int j=1;j<5;j++){
deckOfCard[i][j]= new PeaceCard();
deckOfCard[i][j].Value=i;
deckOfCard[i][j].Suit=j;
}
}
public PeaceCard draw(){
PeaceCard cardDraw= new PeaceCard();
int valueIndex = new Random().nextInt(13)+1;//draw a random card.
int suitIndex = new Random().nextInt(4)+1;
while( deckOfCard[valueIndex][suitIndex].Suit == 0){ //to check if this card is in the deck or not
valueIndex = new Random().nextInt(13)+1;//draw another card.
suitIndex = new Random().nextInt(4)+1;
}
cardDraw.Value = deckOfCard[valueIndex][suitIndex].Value;//assign the value of the drew card into the Card instance
cardDraw.Suit = deckOfCard[valueIndex][suitIndex].Suit;
deckOfCard[valueIndex][suitIndex].Value=0;//mark the drew card's value and suit with zero in the deck,
deckOfCard[valueIndex][suitIndex].Suit=0;//make sure this card won't show up anymore
return cardDraw;
}
}
something isnt right about the code above and can't overrider or do the instruction said
Explanation / Answer
card.java
Deck.java
peacecard.java
public class PeaceCard extends Card {
@Override public boolean winner(Card b){
boolean re=true;
if(this.cardValue > b.cardValue)
re=false;
else if((this.cardValue == b.cardValue)&&(this.suitValue > b.suitValue))
re=false;
return re;
}
}
PeaceDeck.java
mainDriver.java
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.