In Java Write a class encapsulating a sports game, which inherits from Game. A s
ID: 3530965 • Letter: I
Question
In Java Write a class encapsulating a sports game, which inherits from Game. A sports game has the following additional attributes: whether the game is a team or individual game, and whether the game can end in a tie. Code the constructor and the toString method of the new class. You also need to include a client class to test your code.
Explanation / Answer
public class SportsGame extends Game { public SportsGame() { super(); } public String toString() { String output ="hey"; return output; } //Accessors (Getters) public String getGameType() { Scanner scan = new Scanner(System.in); System.out.println("Enter number of players"); int players = scan.nextInt(); if (players > 2) { return "Team"; } else { if (players ==2) { return "Individual"; } else { return "N/A"; } } } public String getCanTie() { String canTie = "yes"; String cantTie = "no"; if (1==1) { return canTie; } else { return cantTie; } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.