Question
Begin with the following class public class Game{ private String name; private int maxNumPlayers; private boolean canEndInTie; private int totalPoints; static final int winningPoints=1000; public
Begin with the following class
public class Game{ private String name; private int maxNumPlayers; private boolean canEndInTie; private int totalPoints; static final int winningPoints=1000; public boolean canEndGame(){ if (totalPoints > winningPoints) return true; else return false; } }
Write a complete Java program that accomplishes the following:
Write a constructor for class Game that initializes 3 of the data members with values passed in as parameters.
Write accessor and mutator methods for the variable canEndInTie.
Make a subclass of Game 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 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).
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.
Modify the CardGame class so that it implements the following interface. (It's up to you to determine the functionality it represents.) interface Playable { boolean canBeginGameNow(int numPlayers); }
Write a main method that does the following: Create an instance of either Game or CardGame. Then call canEndGame on this object. Display a message of either Game can end now. (if canEndGame returned true) or Game cannot end yet. (if canEndGame returned false).
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started