Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: Slot Machine

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Slot Machine

    Hi all,

    Im new to java this year and have been asked to create a small slot machine program for a project. It is a 3 reel slot machine with a few different combinations of winning. I have came across a few problems when coding this I have listed them below.

    1. The program has yet to start up and run. I keep getting these 3 errors and dont no how to fix them. This is in the main application.

     

    C:\Users\Andy\Desktop\Programming\SlotMachine.java :55: cannot find symbol
    symbol : method compute()
    location: class SlotMachine
    mySlot.compute();
    ^
    C:\Users\Andy\Desktop\Programming\SlotMachine.java :94: cannot find symbol
    symbol : method getwinnings()
    location: class SlotMachine
    winnings = mySlot.getwinnings();
    ^
    C:\Users\Andy\Desktop\Programming\SlotMachine.java :97: cannot find symbol
    symbol : method geteuro()
    location: class SlotMachine
    euro = mySlot.geteuro();




    This is the code i have for this part of the program.

    import javabook.*;
     
    class SlotMachine{
    	public static void main(String args[]){
     
    		//Declare objects
     
    		MainWindow mWindow;
    		InputBox iBox;
    		OutputBox oBox;
    		SlotMachine mySlot;
     
    		//Create objects
     
    		mWindow = new MainWindow();
    		iBox = new InputBox(mWindow);
    		oBox = new OutputBox(mWindow);
    		mySlot = new SlotMachine();
     
    		//Show mWindow & oBox
     
    		mWindow.show();
    		oBox.show();
     
    		//Declare Variables
     
    		int euro;
    		int coin;
    		int winnings;
    		int slot1;
    		int slot2;
    		int slot3;
     
     
     
    		//Get Input
     
    		iBox.getInteger();
    		      System.out.println("Enter amount of coins to bet");
     
    			if (coin == 0){
    					System.out.println("Game has ended");
    }
     
     
    		//process
     
     
    		mySlot.compute();
     
    		if (slot1 == 1){
    			oBox.print("Cherry ");
    	}
    		else if (slot1 == 2){
    			oBox.print("Grape ");
    	}
    		else if (slot1 == 3){
    			oBox.print("Bell");
    	}
     
     
    		if (slot2 == 1){
    			oBox.print("Cherry ");
    	}
    		else if (slot2 == 2){
    			oBox.print("Grape ");
    	}
    		else if (slot2 == 3){
    			oBox.print("Bell");
    	}
     
    		if (slot2 == 1){
    			oBox.print("Cherry ");
    	}
    		else if (slot2 == 2){
    			oBox.print("Grape ");
    	}
    		else if (slot2 == 3){
    			oBox.print("Bell");
    	}
     
     
     
     
     
    		//output
     
    		winnings = mySlot.getwinnings();
    			oBox.println("You have Won");
     
    		euro = mySlot.geteuro();
    			oBox.println("Your coins in Euro");
     
    }
    }

    The other part of the program gives me 2 errors!

     

    1.C:\Users\Andy\Desktop\Programming\Slot.java:44: illegal start of expression
    public void setCoin(int c){
    ^
    2.C:\Users\Andy\Desktop\Programming\Slot.java:151: ';' expected
    ^




    This is the code below.

    import javabook.*;
    import java.util.Random;
     
     
     class Slot{
     	private Random slotNumber = new Random();
     
     
     	//Assigning value for each symbol
     
     
    	private final int bell =1;
    	private final int grape =2;
    	private final int cherry =3;
     
    	//Declare Data Members
     
    	private int PayoutMultiplier;
    	private int coin;
    	private int euro;
     
    	private int slot1;
    	private int slot2;
    	private int slot3;
     
    	//Constructor
     
    	public Slot(){
    		coin =0;
    		PayoutMultiplier =0;
    	{
     
     
    	//Set Method
     
    	public void setCoin(int c){
    		coin = c;
    }
    	public void setPayoutMultiplier(int pm){
    		payoutmultiplier = pm;
     
    }
     
     
     
    	//Get Method
     
    	public int getPayoutMultiplier(){
    		return payoutMultiplier;
    	{
     
    	public int getSlot1(){
    		return slot1;
    	{
     
    	public int getSlot2(){
    			return slot2;
    	{
     
    	public int getSlot3(){
    			return slot3;
    	{
     
     
     
    	//Compute
     
    		public void compute(){
     
    		int slot1 = slotNumber.nextInt(3) + 1;
    		int slot2 = slotNumber.nextInt(3) + 1;
    		int slot3 = slotNumber.nextInt(3) + 1;
     
    		if (slot1 == bell && slot2 == bell && slot3 == bell){
    			System.out.println("10");
    			payoutMultiplier = 10;
    	}
    		else if (slot1 == grape && slot2 == grape && slot3 == grape){
    			System.out.println("7");
    			payoutMultiplier = 7;
    	}
     
    		else if (slot1 == cherry && slot2 == cherry && slot3 == cherry){
    			System.out.println ("5"):
    			payoutMultiplier = 5;
    	}
     
    		else if (slot1 == cherry && slot2 == cherry && (slot3 == grape || slot3 == bell)){
    			System.out.println ("3");
    			payoutMultiplier = 3;
    	}
     
    		else if (slot1 == cherry && (slot2 == grape || slot2 == bell) && slot3 == cherry){
    			System.out.println ("3");
    			payoutMultiplier = 3;
    	}
     
    		else if ((slot1 == grape || slot1 == bell) && slot2 == cherry && slot3 == cherry){
    			System.out.println ("3");
    			payoutMultiplier = 3;
    	}
     
    		else if (slot1 == cherry && (slot2 == grape || slot2 == bell)  && (slot3 == grape || slot3 == bell)){
    			System.out.println ("1");
    			payoutMultiplier = 1;
    	}
     
    		else if ((slot1 == grape || slot1 == bell) && slot2 == cherry && (slot3 == grape || slot3 == bell)){
    			System.out.println ("1");
    			payoutMultiplier = 1;
     
    	}
     
    		else if ((slot1 == grape || slot1 == bell) && (slot2 == grape || slot2 == bell) && slot3 == cherry){
    			System.out.println ("1"):
    			payoutMultiplier = 1;
     
    	}
     
    		else if ((slot1 == grape || slot1 == bell) && (slot2 == grape || slot2 == bell) && (slot3 == grape || slot3 == bell)){
    			System.out.println ("No Win")
    			payoutMultiplier = 0;
    	}
     
    		else {
    			System.out.println("No Combination")
    	}
    }
     
     
     
    	//Get Method
     
    	public int getWinnings();{
    		int winnings = payoutMultiplier * coins;
    		return winnings;
    	}
     
    	double geteuro();{
    		int euro = (coins * .25);
    		return euro;
    	}

    Any help with this would be much appreciated i also have to add a loop so the program allows the player to keep using the program until they enter zero so if you could also explain were abouts in the program i am to put the loop it would be great.

    Thanks for taking the time to read this.
    Last edited by nemoisback66; November 17th, 2010 at 06:49 AM.


  2. #2
    Junior Member
    Join Date
    Nov 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Slot Machine

    Ooops didnt mean for it too be so big!!

  3. #3
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: Slot Machine

    This thread has been cross posted here:

    http://www.java-forums.org/new-java/34887-slot-machine-project.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting

    db


  4. #4
    Junior Member
    Join Date
    Nov 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Slot Machine

    Should i delete one post? Jus thought if i put it in more than one forum i mite get a better response??

  5. #5
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Slot Machine

    Quote Originally Posted by nemoisback66 View Post
    Should i delete one post? Jus thought if i put it in more than one forum i mite get a better response??
    No thats fine. Cross posting is allowed, just please read the rules.

    I will take a look at the code now..
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  6. #6
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Slot Machine

    Where can I find the javabook import?

    The errors are quite self explanatory. What IDE are you using?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  7. #7
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Slot Machine

     public int getSlot1(){
            return slot1;
        }
     
        public int getSlot2(){
                return slot2;
        }
     
        public int getSlot3(){
                return slot3;
        }

    Your brackets were off.

    Also, you should have setMethod for every getMethod(). Since you've never set any of the slots, they're all going to return null.

  8. #8
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Slot Machine

    int slot1 = slotNumber.nextInt(3) + 1;
    int slot2 = slotNumber.nextInt(3) + 1;
    int slot3 = slotNumber.nextInt(3) + 1;

    Oh....you do, but why not have that in the get methods? Those are local variables, and it may not like that you have some earlier with the same name before your constructor.

    private int PayoutMultiplier;

    you don't have it capitalized in one of your methods.

    mySlot = new SlotMachine();

    SlotMachine doesn't seem to have a constructor.

  9. #9
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Slot Machine

    double geteuro();{
            int euro = (coins * .25);
            return euro;
        }
    double euro = (coins * .25);

    It should be.

    also, it appears you may be missing an ending bracket after this method, so that you'll reach end of file while parsing or something.

Similar Threads

  1. Moving MySql Database from one machine to another machine
    By vaishali in forum JDBC & Databases
    Replies: 5
    Last Post: July 21st, 2010, 01:21 AM
  2. help with my machine project.
    By Irvine in forum AWT / Java Swing
    Replies: 4
    Last Post: September 1st, 2009, 05:13 AM
  3. need help with Vending Machine code...
    By mia_tech in forum Loops & Control Statements
    Replies: 3
    Last Post: April 20th, 2009, 05:24 AM
  4. Replies: 8
    Last Post: February 24th, 2009, 04:04 PM
  5. Replies: 6
    Last Post: November 14th, 2008, 03:09 PM