Question: Can you help me write a driver test program? I have provided the code I wrote for the requirement. The code I wrote is based

Can you help me write a driver test program?

I have provided the code I wrote for the requirement.

The code I wrote is based on the following requirement :

(the goal is to write a JAVA program that rolls dice for computer games.

The software should be written as a reusable component (class).

The dice roller program should allow a user to specify the number of dice to be rolled as an integer input, and return that many dice rolled randomly.

In a game such as Backgammon or Monopoly, for example, two dice would be used. Risk would use up to three; Yahtzee would use up to five.

So, for example, the method would be called something like this:

roll_dice(1);

which would return three random dice values; e.g.:

4, 1, 5

You can assume your program only needs to roll 6-sided dice.:)

*******************

(I want you to help me write a test driver class which shows test the following 8 cases).

Tests to be run:

1) What if a fractional number is inserted.

2) What if a decimal value is inserted.

3) What if a Letter is entered by the user. (A, B, C, etc)

4) What if negative numbers are entered.

5) What if the number are entered as 2^n?

6) Does the program check for say, doubles or 7s?

7) Is there a reasonable distribution test for 1 die?

8) Reasonable distribution tests for 2 or more dice?

If the test fails can you fix the code with the correction?

*****************************************************************************************************************

import java.util.*;

class Dice

{

// roll n dice and return the output as integer array

public static int[] roll_dice(int n)

{

// create a Random object to generate random value

Random rand = new Random();

int[] arr = new int[n];

int i;

for( i = 0 ; i < n ; i++ )

// generate random number in range 1 - 6

arr[i] = rand.nextInt( ( 6 - 1 ) + 1 ) + 1;

return arr;

}

public static void main(String[] args)

{

// create a Scanner object to get user input

Scanner sc = new Scanner(System.in);

System.out.print("Enter the number of dice to be rolled : ");

// get user input

int n = sc.nextInt();

int[] arr = roll_dice(n);

int i;

System.out.print(" The outcomes are : ");

for( i = 0 ; i < arr.length ; i++ )

System.out.print(arr[i] + " ");

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!