Mark has been assigned a task of developing a bame console. In this game console,he needs to ensure that the following functionalities are implemented:
- Each game in the game console must offer functionalities, such as play game compute score, and display score.
- The display score functionality will remain the same for all the games. However the play game and computer score functionalities will be different for each game.
In the inital phase, you do not need to implement the logic of the functionalities. However, display appropriate message, such as the play game functionality will display the message, Starting the game. Now, help Mark to achive the preceding reguirments.
ANSWER
abstract class GameConsole {
int score;
void displayScore () {
System.out.println("The displayScore method.");
}
abstract void computeScore();
abstract void playGame();
}
class Badminton extends GameConsole {
void playGame() {
System.out.println("Starting the Badmintion Game...");
}
void computeScore() {
System.out.println("Calculating Score for the Badmintion Game...");
}
}
class TableTennis extends GameConsole {
void playGame() {
System.out.println("Starting the TableTennis Game...);
}
void computeScore() {
System.out.println("Calculating Score for the TableTennis Game...");
}
}
public class GameDemo {
public static void main(String args[]) {
Badminton obj1 = new Badminton ();
obj1.playGame();
obj1.computeScore();
obj1.displayScore();
TableTennis obj2 = new TableTennis();
obj2.playGame();
obj2.computeScore();
obj2.displayScore();
}
}
- Each game in the game console must offer functionalities, such as play game compute score, and display score.
- The display score functionality will remain the same for all the games. However the play game and computer score functionalities will be different for each game.
In the inital phase, you do not need to implement the logic of the functionalities. However, display appropriate message, such as the play game functionality will display the message, Starting the game. Now, help Mark to achive the preceding reguirments.
ANSWER
abstract class GameConsole {
int score;
void displayScore () {
System.out.println("The displayScore method.");
}
abstract void computeScore();
abstract void playGame();
}
class Badminton extends GameConsole {
void playGame() {
System.out.println("Starting the Badmintion Game...");
}
void computeScore() {
System.out.println("Calculating Score for the Badmintion Game...");
}
}
class TableTennis extends GameConsole {
void playGame() {
System.out.println("Starting the TableTennis Game...);
}
void computeScore() {
System.out.println("Calculating Score for the TableTennis Game...");
}
}
public class GameDemo {
public static void main(String args[]) {
Badminton obj1 = new Badminton ();
obj1.playGame();
obj1.computeScore();
obj1.displayScore();
TableTennis obj2 = new TableTennis();
obj2.playGame();
obj2.computeScore();
obj2.displayScore();
}
}
No comments:
Post a Comment