Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone help write a JUnit4 Tester for this die roll class. import java.util.Random; public class Die { public static final int DEFAULT_SIDES = 6;

Can someone help write a JUnit4 Tester for this die roll class.

import java.util.Random;

public class Die { public static final int DEFAULT_SIDES = 6; private static Random ourRandNumGen = new Random(); private final int iMyNumSides; private int iMyResult;

public Die() { this(DEFAULT_SIDES); }

public Die(int numSides) { iMyNumSides = numSides; iMyResult = 1; }

public int roll() { iMyResult = ourRandNumGen.nextInt(iMyNumSides) + 1;

return iMyResult; }

public int getNumSides() { return iMyNumSides; }

public int getResult() { return iMyResult; }

public boolean equals(Object otherObj) { boolean result = true; if (otherObj == null) result = false; else if (this == otherObj) result = true; else if (this.getClass() != otherObj.getClass()) result = false; else { Die otherDie = (Die) otherObj; result = this.iMyResult == otherDie.iMyResult && this.iMyNumSides == otherDie.iMyNumSides; } return result; }

public String toString() { return "Num sides " + getNumSides() + " result " + getResult();

using these test methods:

image text in transcribed

You will create two different objects: a default and one with 5-sides. A default object is created with the default constructor and the 5-sided die with the one-parameter constructor. The tester files should have the following test cases: Test Method testDefaultRoll test5SideRoll Description Tests the roll of a die with the default sides Tests the roll of a die with 5 sides Tests the getNum Sides of default die Tests the getNumSides of a 5-sided die Tests the result of a default die testDefaultNum Sides test5Num Sides testGetDefaultResult testGet5SideResult Test the result of a 5 sided die testEquals True Test two equal objects testEquals False Test two different (not equal) objects testDefaultToString Test the toString for default die Test the toString for a 5-sided die test5SideToString Example: If you are trying to implement testDefaultRoll: 1 @Test 2 public void testDefaultRoll() { 3 4 }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Database Programming With Visual Basic.NET

Authors: Ying Bai

1st Edition

0521712351, 978-0521712354

More Books

Students also viewed these Databases questions

Question

music 101 composition project

Answered: 1 week ago

Question

18. If you have power, then people will dislike and fear you.

Answered: 1 week ago