Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For this progam we need the lower value for the winning card or player: we hava

ID: 642259 • Letter: F

Question

For this progam we need the lower value for the winning card or player:

we hava peace card method which is the derivate class of card. the new class will override the winner () class but will reuse others method from card

second we have peacedeck same as above but with deck and new class will use a constructor that initialize the superclass array of card and same will reuse all method or function in deck.

This is was I got so far:

//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;

}

}

// main is self explenatory

Explanation / Answer

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; } } public class PeaceDeck extends Deck { public PeaceDeck() { for(int i=1;i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote