Jcreator Slot Machine Help!

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

37 Replies - 804 Views - Last Post: 18 May 2014 - 02:20 PM Rate Topic: ***-- 2 Votes

#1 Troubles  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 31
  • Joined: 18-May 14

Jcreator Slot Machine Help!

Posted 18 May 2014 - 08:09 AM

I pulled off an all nighter in order to finish off this project for my computer studies
class but i keep getting an error cannot find symbol at line 96?


import java.io.*;
import java.util.*; 
import java.util.Random;
public class SlotMachine {
    //Generates 3 random numbers for slot machine
    public static void main(ArrayList<Integer> slotMachine) {
    
    int count = 0;
    while (count<3)	
    
    {
    Random slot = new Random();
    int slotNumber= slot.nextInt(10)+1;
    slotMachine.add(slotNumber);
    count+=1;
    }	
    return;	
    }//End of slotNumbers method	
    
    //Determine points earned on slot machine
    public static int winnings(ArrayList<Integer> slotMachine)
    {
    int number1= slotMachine.get(0);
    int number2= slotMachine.get(1);
    int number3= slotMachine.get(2);
    int points;
    
    //if three 7's
    if (number1==7 && number2==7&& number3==7)
    {
    points=750;
    return points;
    }
    
    //if three matches
    if (number1==number2 && number1==number3 && number2==number3)
    {
      points=75;
      return points;
    
    }
    
    //if two matches 
    if(number1==number2 || number1==number3 || number2==number3)
    {
       if(number1==7 && number2==7)
       {
       	points=20;
       	return points;
    }
    
    else if (number2==7 && number3==7)
    {
    points= 20;
    return points;
    
    }	
    }
    else
    {
    points = 5;
    return points;
    }
    
   }//End of winnings method	
   
   public static void main(String[] args) throws InterruptedException
   {
   int userPoints;
   int points;
   Scanner input = new Scanner(System.in);
   
   //Allow user to enter in points brought to play.
   System.out.println("Enter amount of playable points: ");
   userPoints = input.nextInt();
   input.nextLine();
   
   while (userPoints>0)
   {
      System.out.println("Spin? (Yes/No)");
      String answer = input.nextLine();
      if (answer.equalsIgnoreCase("Yes"))
      {
         userPoints-=1;//Take point for spin
         ArrayList<Integer>slotMachine = new ArrayList<Integer>();
         
         //Obtain random 3 numbers.
         slotNumber(slotMachine);
         
         //Obtain points earned.
         points=winnings(slotMachine);
         userPoints+=points;
         
         //Timing for slot numbers
         for(int i=0; i<3; i++)
         {
         
         System.out.print(slotMachine.get(i) + " ");
         }	
         	
         //Display points won
         System.out.println("\nPoints won: " +points);
         System.out.println("Ponts left: " +userPoints);
      	}	 
   
       else if (answer.equalsIgnoreCase("No"))
       {
       System.out.println("Thanks for playing!");
       System.out.println("Points left: " +userPoints);
       System.out.println("Thank you for playing.");
       break;
       }	
   
   
   
   }	
   
}	
   
   
    
}



srry the error occurs in line 88

Is This A Good Question/Topic? 0
  • +

Replies To: Jcreator Slot Machine Help!

#2 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2777
  • View blog
  • Posts: 11,757
  • Joined: 20-September 08

Re: Jcreator Slot Machine Help!

Posted 18 May 2014 - 08:20 AM

The method slotNumber is undefined in your code
Was This Post Helpful? 0
  • +
  • -

#3 Troubles  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 31
  • Joined: 18-May 14

Re: Jcreator Slot Machine Help!

Posted 18 May 2014 - 08:51 AM

View Postg00se, on 18 May 2014 - 08:20 AM, said:

The method slotNumber is undefined in your code


yea but how do i solve this?
Was This Post Helpful? 0
  • +
  • -

#4 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2777
  • View blog
  • Posts: 11,757
  • Joined: 20-September 08

Re: Jcreator Slot Machine Help!

Posted 18 May 2014 - 08:55 AM

By defining it? (Or not calling it until it IS defined)

This post has been edited by g00se: 18 May 2014 - 08:56 AM

Was This Post Helpful? 0
  • +
  • -

#5 Troubles  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 31
  • Joined: 18-May 14

Re: Jcreator Slot Machine Help!

Posted 18 May 2014 - 08:57 AM

View Postg00se, on 18 May 2014 - 08:55 AM, said:

By defining it? (Or not calling it until it IS defined)


yea srryim just a beginner at this couuld u just show me how to define slotNumber
Was This Post Helpful? 0
  • +
  • -

#6 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2777
  • View blog
  • Posts: 11,757
  • Joined: 20-September 08

Re: Jcreator Slot Machine Help!

Posted 18 May 2014 - 09:19 AM

You could rename the first (badly named) method main to slotNumber
Was This Post Helpful? 1
  • +
  • -

#7 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 731
  • View blog
  • Posts: 3,173
  • Joined: 03-December 12

Re: Jcreator Slot Machine Help!

Posted 18 May 2014 - 09:21 AM

Quote

018}//End of slotNumbers method


You have a main method that ends with this. Is that what you thought your slotNumber method was?
Was This Post Helpful? 1
  • +
  • -

#8 Troubles  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 31
  • Joined: 18-May 14

Re: Jcreator Slot Machine Help!

Posted 18 May 2014 - 10:21 AM

[quote name='g00se' date='18 May 2014 - 09:19 AM' timestamp='1400429973' post='2011964']
You could rename the first (badly named) method main to slotNumber
[/quote

I changed it but it didnt do the trick.

View Postastonecipher, on 18 May 2014 - 09:21 AM, said:

Quote

018}//End of slotNumbers method


You have a main method that ends with this. Is that what you thought your slotNumber method was?


Well i tried to fix it but its a real headscratcher.
Was This Post Helpful? 0
  • +
  • -

#9 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 731
  • View blog
  • Posts: 3,173
  • Joined: 03-December 12

Re: Jcreator Slot Machine Help!

Posted 18 May 2014 - 10:38 AM

Your program logic is a little ackward. And follow an indention style, it is hard to link what goes with what. Are you receiving the same error? Post your updated code for follow up.

It looks like your logic should follow:


  • Ask user for bank amount.
  • Start game
  • Get and display 3 random numbers.
  • Total points
  • Add points to bank
  • Repeat.


Your current problem is, getting the random number?
Was This Post Helpful? 1
  • +
  • -

#10 Troubles  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 31
  • Joined: 18-May 14

Re: Jcreator Slot Machine Help!

Posted 18 May 2014 - 11:17 AM

View Postastonecipher, on 18 May 2014 - 10:38 AM, said:

Your program logic is a little ackward. And follow an indention style, it is hard to link what goes with what. Are you receiving the same error? Post your updated code for follow up.

It looks like your logic should follow:


  • Ask user for bank amount.
  • Start game
  • Get and display 3 random numbers.
  • Total points
  • Add points to bank
  • Repeat.


Your current problem is, getting the random number?


yes u got it all spot on but the thing is i didnt really change anything to the program becuz im too novice could u assist
Was This Post Helpful? 0
  • +
  • -

#11 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 731
  • View blog
  • Posts: 3,173
  • Joined: 03-December 12

Re: Jcreator Slot Machine Help!

Posted 18 May 2014 - 11:45 AM

Remove your imitation main method. Recreate it under slotNumber.

You then need to create the random number and return it to the calling function. I don't get the idea of calling it with the parameter as it wont do what you think it will.


slotNumber int() {

    Random r = new Random();
    int num = ( r.nextInt( 10 ) * 1 );
    
    return num;

}



Then call the function the number of times you need a number.
Was This Post Helpful? 0
  • +
  • -

#12 Troubles  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 31
  • Joined: 18-May 14

Re: Jcreator Slot Machine Help!

Posted 18 May 2014 - 11:55 AM

View Postastonecipher, on 18 May 2014 - 11:45 AM, said:

Remove your imitation main method. Recreate it under slotNumber.

You then need to create the random number and return it to the calling function. I don't get the idea of calling it with the parameter as it wont do what you think it will.


slotNumber int() {

    Random r = new Random();
    int num = ( r.nextInt( 10 ) * 1 );
    
    return num;

}



Then call the function the number of times you need a number.



could u add this to my program please im lost.

Thing is i wuz taught this way and ur suggestion seems right but i still dont see it
Was This Post Helpful? 0
  • +
  • -

#13 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 731
  • View blog
  • Posts: 3,173
  • Joined: 03-December 12

Re: Jcreator Slot Machine Help!

Posted 18 May 2014 - 11:57 AM

You just need to add it to your class and call it when needed.
Was This Post Helpful? 0
  • +
  • -

#14 Troubles  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 31
  • Joined: 18-May 14

Re: Jcreator Slot Machine Help!

Posted 18 May 2014 - 12:59 PM

View Postastonecipher, on 18 May 2014 - 11:57 AM, said:

You just need to add it to your class and call it when needed.

example please
Was This Post Helpful? 0
  • +
  • -

#15 astonecipher  Icon User is offline

  • Major DIC Head
  • member icon

Reputation: 731
  • View blog
  • Posts: 3,173
  • Joined: 03-December 12

Re: Jcreator Slot Machine Help!

Posted 18 May 2014 - 01:02 PM

How do you add a method to a class? How do you add any code to a class? How do you call a method?
These are things you are already doing in your code.
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3