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

write java(OOP) CODE if (totalPoints > winningPoints) return true: Write a compl

ID: 3902033 • Letter: W

Question

write java(OOP) CODE

if (totalPoints > winningPoints) return true: Write a complete Java program that accomplishes the following 1. Write a constructor for class Game that initializes 3 of the data members with values passed in as 2 Write accessor and mutator methods for the variable canendintie. [8 points] 3. Make a subclass of Game called CardGame. A card game keeps track of the number of cards that remain in the central stack. This s subclass should have a constructor that accepts parameters to assign values to the number of cards currently in the stack, and whether it can end in a tie (a data member of the Game class). [8 points] CardGame is different than Gome in that it is over when the stack of cards has been depleted When the method canEndGame is called on a CardGame object, it should reflect this difference 14 points 4. Modity the CaraGame class so that it implements the following interface (It's up to you to determine the functionality it represents) Create an instance of either Game or CardGame Then call ca ame r 8 points] 3 (12pt)T

Explanation / Answer

Below is your code. I have tried implementing everything. Please let me know in comments if I have missed anything. I'll update the code..

Please do rate this answer positive, If i was able to help you. Let me know if you have any issues in comments

Game.java

public class Game {

private String name;

private int maxNumPlayers;

private boolean canEndInTie;

public Game() {

name = "Default Game";

maxNumPlayers = 0;

canEndInTie = true;

}

public Game(String name, int maxNumPlayers, boolean canEndInTie) {

this.name = name;

this.maxNumPlayers = maxNumPlayers;

this.canEndInTie = canEndInTie;

}

private int totalPoints;

static final int winningPoints = 1000;

public boolean isCanEndInTie() {

return canEndInTie;

}

public void setCanEndInTie(boolean canEndInTie) {

this.canEndInTie = canEndInTie;

}

public boolean canEndGame() {

if (totalPoints > winningPoints)

return true;

else

return false;

}

}

CardGame.java

public class CardGame extends Game implements Playable {

private int numOfCardsInStack;

public CardGame(int numOfCardsInStack, boolean canEndInTie) {

this.numOfCardsInStack = numOfCardsInStack;

this.setCanEndInTie(canEndInTie);

}

@Override

public boolean canEndGame() {

if (numOfCardsInStack <= 0)

return true;

else

return false;

}

@Override

public boolean canBeginGameNow(int numPlayers) {

if (numPlayers > 1) {

return true;

} else {

return false;

}

}

public static void main(String[] args) {

Game gm = new Game("PlayMate", 10, true);

if (gm.canEndGame()) {

System.out.println("Game can end now.");

} else {

System.out.println("Game cannot end yet.");

}

CardGame cgm = new CardGame(0, true);

if (cgm.canEndGame()) {

System.out.println("Game can end now.");

} else {

System.out.println("Game cannot end yet.");

}

}

}

Playable.java

interface Playable {

boolean canBeginGameNow(int numPlayers);

}

Output

Game cannot end yet.
Game can end now.