I need to code a program for my friend and it has been giving me some difficulties. This needs to have two classes, one called Tester and another called Game. And the data in the Game class needs to be pulled to the tester class after the calculations are finished. The tester class out puts the sum of the two dice added together. Here are the directions:

Directions: You are to write a class that represents a single di. Your class will contain a class variable that indicates the current side of the di. It will contain a method that randomly rolls the die, changing the class variable. You may add any other methods that help you in designing the game below.

You will use your class to write the game of lucky 7. A player will start out with 25 credits. The player then rolls 2 di, if the total of the die equals 7 the player wins 4 credits. If the total is not 7 then the player loses 1 credit. You will display how many time they have played along with their balance before the game starts and after each turn. You will need to prompt the user if they would like to continue or quit. To get the number of the die, you must use the Math.random function.


Here is what I have came up with so far, and I have only came up with how to prompt the user to quit or continue.

GAME CLASS

public class Game
{
   // Declair the variables
   int intCredits;
   int intNumber = ((int)(Math.random() * 6));
   
    // constructor(Sets up the class)
    public Game(int myCredits)
    {
        intCredits = myCredits;
    } 
    
    // Method to get a random number
    public int Number(int randomNumber)
    {
        intNumber =((int)(Math.random() * 6)) ;
        
        return intNumber;
    }
    public void intNumber(int diNumber)
    {
        intNumber = intNumber * 2;
    }
    public int returnNumber()
    {
        return intNumber;
    }
}

TESTER CLASS

import java.util.*;

public class Tester
{
  public static void main(String args[])
  {
    
      // Declair variables
      int intContinue;

      // Declair a scanner
      Scanner sc = new Scanner(System.in);
      
      do
      {
      Game myGame = new Game(25);
      myGame.Number(((int)(Math.random() * 6)));

      int Dice_Number = myGame.returnNumber();
      System.out.println(Dice_Number);
      // Prompt the user
      System.out.println("Press 1 to quit of 2 to continue:   ");
      
      // Get the answer
      intContinue = sc.nextInt();
      
    } while (intContinue !=1);
    }
}

THANKS!!
I would greatly appreciate it if this could be done by 5/31/10

I would greatly appreciate it if this could be done by 5/31/10

OMG

"Do not post homework problems expecting a quick answer without showing any effort yourself."

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.