Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Task Inside src / main / java / random , in Game.java there is an unimplemented function named battle. This function should return true if
Task
Inside srcmainjavarandom in Game.java there is an unimplemented function named battle. This function should return true if the hero wins the battle and false if they lose. The chance of the hero winning is
There are two constructors for the class; one for testing where the random attribute is seeded with the given value, and a default constructor which uses the current time as the seed. The default constructor is for real usage for example, the main method we have provided
When the Random object is constructed with a seed of the following values are the results first calls to nextInt:
For :
For :
Write at least unit tests for battle inside GameTest.java using seeds.
Once you have done this, implement the function.
How would you write tests for Game with the default constructor that prove the battle function works as expected? Think about this and be prepared to answer during marking. Write your answer down in your blog postpackage random;
import java.util.Random;
A simple game, where a hero engages in battles. The hero has an equally
likely chance of succeeding as of failing.
@author Nick Patrikeos @your name
public class Game
private Random random;
public Gamelong seed
random new Randomseed;
public Game
thisSystemcurrentTimeMillis;
public boolean battle
TODO
int randomNumber random.nextInt;
return randomNumber ;
public static void mainString args
Game g new Game;
for int i ; i ; i
if gbattle
System.out.printlnWe won!! You are awesome!!";
else
System.out.printlnLost :;
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