write the java code f (totaiPointa > winningPointa) return sFue else recurn fals
ID: 3902034 • Letter: W
Question
write the java code
f (totaiPointa > winningPointa) return sFue else recurn falsei 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 parameters [6 points) 2. Write accessor and mutator methods for the variable canendinTie. [8 points 3 Make a subclass of Gome called CardGame. A card game keeps track of the number of cards that remain in the central stack. This subclass should have a constructor that accepts para values to the number of cards currently in the stack, and whether it can end in a tie (a data member of the Gane class) 18 points] CardGame is different than Game 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. [4 poir 4 Modily the CaraGaze class so that implements the following interface (t's up to you to determine the functionality it represents) interface Playabie boolean canBeginGameNowint numPlayers) (6 points Create an instance of either Game or araseme 5. Write a main method that does the following Then call canEndGame on this object Display a 8 points message of either Game can end now if canEndGame returned crue) or Game cannot end yet (if canEndGame returned talse).Explanation / Answer
// Note: Save program as CardGame.java
//Game.java
class Game {
//Data Members
boolean canEndInTie;
String cardType, cardName;
int numberOfCards;
//Constructor with sample members
public Game(String cardType,String cardName,int numberOfCards){
this.cardType=cardType; //Initializing variables
this.cardName=cardName;
this.numberOfCards=numberOfCards;
}
//Accessors and Mutators of canEndInTie
public boolean isCanEndInTie() {
return canEndInTie;
}
public void setCanEndInTie(boolean canEndInTie) {
this.canEndInTie = canEndInTie;
}
}
//Playable.java
//Interface Playable contains abstract method
interface Playable {
boolean canBeginGameNow(int numPlayers);
}
//CardGame.java
// Subclass CardGame extends Game
// CardGame implements Playable
public class CardGame extends Game implements Playable{
int numOfCards;
//Constructor
public CardGame(String cardType, String cardName, int numOfCards) {
//Calling super class constructor
super(cardType, cardName, numOfCards);
//Initializing super class value to current class value
this.numOfCards = super.numberOfCards;
}
// Method canEndGame returns boolean
public boolean canEndGame(){
if(numOfCards==0)
return true;
else
return false;
}
//Overriding method of interface Playable
@Override
public boolean canBeginGameNow(int numPlayers) {
return false;
}
//Main method
public static void main(String args[]) {
//Object of CardGame passing parameters
CardGame cardGame = new CardGame("Heart","Queen",0);
//Calling canEndGame method returns true value
boolean value = cardGame.canEndGame();
if(value==true)
System.out.println("Game can end now..");
else
System.out.println("Game cannot end yet..");
}
}
// Execution :
//Output:
javac CardGame.java
java CardGame
Game can end now..
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.