Status: Not Started
  • Game.java
  • GameTester.java
  • Level.java
Font Size
14
Parentheses autocomplete
Wrap lines
Editor
Theme
Code with blocks by default
Console Font Size
12
Console Theme
Display Server Graphics Screen
Show File Tab Bar
Debug Mode
7 Game Complete (run code)
GameTester.java
public class GameTester
{
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Output
Grading
Docs
Exercise
More
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Pass Test Message

Errors:

This student is viewing this assignment in English. View this page in English?

5 points

This question involves simulation of the play and scoring of a single-player video game. In the game, a player attempts to complete three levels. A level is the game is represented by the Level class.


public class Level

{

/** Returns true if the player reached the goal

* on this level and returns false otherwise

*/

public boolean goalReached()

{ /* implementation not shown */ }


/** Returns the number of points (a positive integer)

* recorded for this level

*/

public int getPoints()

{ /* implementation not shown */ }

}


Play of the game is represented by the Game class. You will write two methods of the Game class.


public class Game

{

private Level levelOne;

private Level levelTwo;

private Level levelThree;


/** Postcondition: All instance variables have

* been initialized.

*/

public Game()

{ /* implementation not shown */ }


/** Returns true if this game is a bonus game

* and returns false otherwise

*/

public boolean isBonus()

{ /* implementation not shown */ }


/** Simulates the play of this Game (consisting of

* three levels) and updates all relevant game data

*/

public void play()

{ /* implementation not shown */ }


/** Returns the score earned in the most recently

* played game, as described in part (a)

*/

public int getScore()

{ /* to be implemented in part (a) */ }


/** Simulates the play of num games and returns the

* highest score earned as described in part (b)

* Precondition: num > 0

*/

public int playManyTimes(int num)

{ /* to be implemented in part (b) */ }

// There may be instance variables, constructors,

// and methods that are not shown.

}


Part (a)


Write the getScore method, which returns the score for the most recently played game. Each game consists of three levels. The score for the game is computed using the following helper methods.

  1. The isBonus method of the Game class returns true if this bonus is a bonus game and returns false otherwise.
  2. The goalReached method of the Level class returns true if the goal has been reached on a particular level and returns false otherwise.
  3. The getPoints method of the Level class returns the number of points recorded on a particular level. Whether or not recorded points are earned (including in the game score) depends on the rules of the game, which follow.


The score for the game is computed according to the following rules.

  1. Level one points are earned only if the level one goal is reached. Level two points are earned only if both the level one and level two goals are reached. Level three points are earned only if the goals of all three levels are reached.
  2. The score for the game is the sum of the points earned for levels one, two, and three.
  3. If the game is a bonus game, the score for the game is tripled.


The following table shows some examples of game score calculations.


Complete the getScore method.


Part (b)


Write the playManyTimes method, which simulated the play of num games and returns the highest game score earned. For example, if the four plays of the game that are simulated as a result of the method call playManyTimes(4) earn scores of 75, 50, 90, and 20, the the method should return 90.


Play of the game is simulated by calling the helper method play. Note that if play is called only one time following multiple consecutive calls to getScore, each call to getScore will return the score in a single simulated play of the game.


Complete the playManyTimes method. Assume that getScore works as intended, regardless of what you wrote in part (a). You must call play and getScore appropriately in order to receive full credit.

Reset Code

Slides and Notes

No slides available for this video

About

Java (main)
Java Version 1.8.0_222