Java HELP ME!!!!

  • Thread starter toyomatt84
  • 2 comments
  • 3,898 views
Java Hates me, I swear it. Could somebody help me out with this one. I am required to write a java program that displays a simple Slot machine function. Here's the direct instructions:

Design and implement an application that simulates a simple slot machine in which three numbers between 0 and 9 are randomly selected and printed side by side. Print an apprpriate statement if all three numbers are the same, or if any two of the numbers are the same. Continue playing until the user chooses to stop.

I have this so far, but I'm stuck in the mud. :( Please help!!!

// *************************************************************************
// Slot Program v1.0
// Programmer: Matt Bertelson
// Date: Feb. 29 2004
// The design behind this program is to select 3 numbers from 0-9 randomly.
// The program repeats itself until the user is done.
// The program also needs to print out appropriate answers for multiples.
// *************************************************************************

import cs1.Keyboard;

public class Slot
{
private Random gen;

public Slot()
{
gen = new Random(); // create random number generator
}
public static void main (String[] args)
{
int a; //first number
int b; //second number
int c; //third number

// Print a program header
System.out.println ();
System.out.println ("Slot Machine");
System.out.println ();

a = gen.nextInt();
b = gen.nextInt();
c = gen.nextInt();

if (a = b = c);
System.out.println ("HOLY COW! You got Triples!!!");
if (a = b);
System.out.println ("You got doubles!");
if (a = c);
System.out.println ("You got doubles!");
if (b = c);
System.out.println ("You got doubles!");

// Print the results
System.out.println ();
System.out.println (a, b, c);
System.out.println ();
}
}
 
Originally posted by toyomatt84
Java Hates me, I swear it. Could somebody help me out with this one. I am required to write a java program that displays a simple Slot machine function. Here's the direct instructions:



I have this so far, but I'm stuck in the mud. :( Please help!!!

Well, I can see that that won't run. I cant complie it because I dont have the cs1.keyboard library, but these improvements should help it somewhat. My AIM is skip0110 if you need more help. (Or just post a reply as to what the errors are.)

Code:
// *************************************************************************
// Slot Program v1.0
// Programmer: Matt Bertelson
// Date: Feb. 29 2004
// The design behind this program is to select 3 numbers from 0-9 randomly.
// The program repeats itself until the user is done.
// The program also needs to print out appropriate answers for multiples.
// *************************************************************************

import cs1.Keyboard;

public class Slot
{
  private Random gen;
  
  public Slot()
    {
        gen = new Random();                             // create random number generator
    }

    public Random getSlot() {
          return gen;
    }

  public static void main (String[] args)
    {
      int a; //first number
      int b; //second number
      int c; //third number
     
     Slot mySlot = new Slot();

      // Print a program header
      System.out.println ();
      System.out.println ("Slot Machine");
      System.out.println ();
      
      a = mySlot.getRandom().nextInt();
      b = mySlot.getRandom().nextInt();
      c = mySlot.getRandom().nextInt();
      

      // Print the results
      System.out.println ();
      System.out.println (a+" "+b+" "+c);
      System.out.println ();


      if ((a==b)&&(b==c))
      System.out.println ("HOLY COW! You got Triples!!!");
      if ((a == b) || (a==c) || (b==c))
      System.out.println ("You got doubles!");
      
    }
}

again, feel free to ask if you dont undrstand anything I did! :)
 
Back