Question
Write Java code for the following problems and place it underneath the problem description. You should use good programming practices, include good names and spacing.
Write Java code for the following problems and place it underneath the problem description. You should use good programming practices, include good names and spacing. The harder it is to read and understand your code, the less points you will earn. You may code it in Eclipse to ensure your syntax is correct but put your solution in this document underneath the problem. You may have to make assumptions in some cases, especially if there is not enough information. If you do assume something, be sure to state the assumption. Note: An assumption does not guarantee that your solution is automatically correct, but it helps in determining partial credit.
Use the following code to answer the following problems.
public abstract class Game {
private String title;
private String description;
public Game(String title, String description) {
this.title = title;
this.description = description;
}
public void setTitle(String title) {
this.title = title;
}
public void setDescription(String description) {
this.description = description;
}
public String getTitle() {
return this.title;
}
public String getDescription() {
return this.description;
}
}
1. Write a Java class to encapsulate the concept of a PC-based game, which is a Game. The class should include:
- Private instance variables of memory (minimum amount of RAM megabytes needed), harddrive (minimum amount of disk megabytes needed), and the CPU (minimum processor speed needed in gigahertz).
- A constructor that initializes all variables to values passed in as arguments
- An accessor (i.e. getter) method for each variable, including the Game variables
- A mutator (i.e. setter) method for each variable, including the Game variables
- A toString method that will return the current state (i.e. values) of the variables as a string
2. Write a Java class to encapsulate the concept of a board game, which is a Game. The class should include:
- Private instance variables of the number of players and an array of integer scores, one element for each player
- A constructor that initializes all variables to values passed in as arguments, except the array
- The array should be instantiated in the constructor and initialized to zero for all players
- An accessor method for each variable
- The score accessor should return the entire array (not individual scores)
- A mutator method for each variable
- The score mutator should take two arguments, the index and score.
- An equals method that will compare the total player scores (i.e. sum all the players in array) to the total player scores in another board game object passed in as an argument. This should return true if the totals match or false if they do not.
- A toString method that will return the title, description, and the scores for each player as a string
3. Write a Java class to encapsulate the concept trivia board game, which is a board game. The class should include:
- Private instance variables of prize money and the number of questions in the game.
- A constructor that initializes all variables to values passed in as arguments
- An accessor method for each variable
- A mutator method for each variable
- A toString method that will return the title, description, the scores for each player, and the prize money as a string
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