954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Java Game

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

zreed
Newbie Poster
3 posts since May 2010
Reputation Points: 10
Solved Threads: 0
 
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."

CrazyDieter
Junior Poster
108 posts since Jul 2005
Reputation Points: 11
Solved Threads: 6
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: