I have written my first class and I was given a driver program to test my class it might seem silly but how do I run the driver file to test my class

Description:
Java Class Die that will manage a roll of a six-sided die. The Class will include a separate method to perform each of the following:

1. Roll one die and return the value.
2. Return the sum of a pair of dice rolled.
3. Roll a pair of dice and return a true if doubles has been rolled.
4. Roll a pair of dice and return the face value if doubles has been rolled.


Driver file

public class TestDie
{
                public static void main (String [ ] args)
                {
                                //Local Constants
                                final int MAX_ROLLS = 1000;     //Maximum number of rolls

//Local Variables
int num1, num2;                 //dice
int total;                              //sum of a roll
boolean doubles;              //true if doubles has been rolled
int numDoubles;               //number of doubles rolled
int doubleValue;               //face value if doubles has been rolled

//Instantiate two Objects of the external Class Die
Die die1 = new Die( );      //create one die Object of Class Die
Die die2 = new Die( );      // create a second die Object of Class Die

//Test the roll of one die
num1 = die1.roll( );
num2 = die2.roll ( );
System.out.println("You have rolled a " + num1 + " and a " + num2);

//Test returning the sum of a roll of a pair of dice
total = die1.sum(num1, num2);
System.out.println("You have rolled a " + total);

//Test for number of doubles rolled out of 1000
for (int numRolls = 1; numRolls <= MAX_ROLLS; numRolls++)
{
                //Roll two dice
num1 = die1.roll( );
num2 = die2.roll ( );
                //Determine if doubles has been rolled
                doubles = die1.isDoubles(num1, num2);
if (doubles == true)
numDoubles++;
                                }
                                //Display number of doubles rolled
System.out.println("You have rolled " + numDoubles + " doubles.");

//Test for face value if doubles is rolled
do
{
                //Roll two dice
num1 = die1.roll( );
num2 = die2.roll ( );
                //Determine if doubles has been rolled
doubleValue = die1.faceValue(num1, num2);
                                }
                                while (doubleValue == 0); //Stop when doubles rolled

                                //Display face value of doubles
System.out.println("You have rolled a double " + doubleValue + ".");
                }//end main
			}

my class file

//Prologue Section
/**********************************************************************
*Program Name:   CSC 111 Program 3
*Author:    Peter Welch
*Date:     3/18/11
*Course/Section:  CSC 111-001 (002w)
*Program Description:
*Java Class Die that will manage a roll of a six-sided die.  The Class will include a separate method to perform each of the following:
*
*1.	Roll one die and return the value.
*2.	Return the sum of a pair of dice rolled.
*3.	Roll a pair of dice and return a true if doubles has been rolled.
*4.  Roll a pair of dice and return the face value if doubles has been rolled.
*
*Initial Algorithm:
*
*BEGIN Program 3
*Public  Die( )
*Public int roll( )
*Public sum (int first, int second)
*Public isDoubles(int first, int second)
*Public faceValue(int first, int second)
*
*END Program 3
 *********************************************************************/

 //Pre-Processor Declaration Section

 import java.util.Random;

 public class Die // begin class definition
 {

		 final int MAX = 6;

		 int faceValue;

		 public  Die() // constructor
		 {

		 }

		 public int roll()// roll of the 6 sided die
		 {
			 Random generator = new Random();

			 faceValue= generator.nextInt(6) +1;

			 return faceValue;
		 }

		 public int sum (int num1, int num2)
		 {
			 int sum;
			 sum = num1 + num2;
			 return sum;
		 }
		 public Boolean isDoubles(int num1, int num2)
		 {
			 if (num1 == num2)
			 return true;
			 else return false;
		 }
		 public int faceValue(int num1, int num2)
		 {
			 return faceValue;
		 }



 }
java TestDie

If you're using eclipse. Right click on TestDie and say Run as->Java Application.

PS: Usage of drivers is stone age. In the new world they use JUnits.

This article has been dead for over six months. Start a new discussion instead.