Results 1 to 12 of 12
Thread: Slot Machine Project
- 11-17-2010, 11:06 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 7
- Rep Power
- 0
Slot Machine Project
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.
The other part of the program gives me 2 errors!Java Code: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"); } }
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.
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.Java Code: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; }
Thanks for taking the time to read this.
- 11-17-2010, 12:17 PM #2
Senior Member
- Join Date
- Aug 2010
- Posts
- 127
- Rep Power
- 0
He probably expected an ';' after this line. Can't help you with the rest of the errorsJava Code:System.out.println("No Combination")
- 11-17-2010, 12:24 PM #3
Member
- Join Date
- Nov 2010
- Posts
- 7
- Rep Power
- 0
Thanks probably have a few errors in it. Main problem is to get it to run. Thanks
- 11-17-2010, 12:52 PM #4
Cross posted
Slot Machine - Java Programming Forums
db
- 11-17-2010, 12:57 PM #5
Member
- Join Date
- Nov 2010
- Posts
- 7
- Rep Power
- 0
Should i delete this thread and just keep it in one or the other?
- 11-17-2010, 01:23 PM #6
Member
- Join Date
- Aug 2010
- Posts
- 5
- Rep Power
- 0
Probably
In SlotMachine.java
The Definition of three methods are missing . so that only the error comes.
You missed the Definition
In slot.java
That contains some constructor and methods are not properly closing u are opened as "{"
and close as "{"
for Example You see the Line 19 on Slot.java
- 11-17-2010, 01:32 PM #7
Member
- Join Date
- Nov 2010
- Posts
- 7
- Rep Power
- 0
Can you help me with what methods I am missing im completely lost now! I fixed the opening and closing tags.
- 11-17-2010, 01:48 PM #8
Last edited by j2me64; 11-17-2010 at 01:54 PM.
- 11-17-2010, 02:07 PM #9
Member
- Join Date
- Nov 2010
- Posts
- 7
- Rep Power
- 0
Hi fixed that now getting a few different errors!
Java Code:C:\Users\Andy\Desktop\Programming\Slot.java:142: <identifier> expected public int .getWinnings();{ ^ C:\Users\Andy\Desktop\Programming\Slot.java:147: <identifier> expected double .getEuro(); ^ C:\Users\Andy\Desktop\Programming\Slot.java:149: illegal start of type return Euro; ^ C:\Users\Andy\Desktop\Programming\Slot.java:149: <identifier> expected return Euro; ^ C:\Users\Andy\Desktop\Programming\Slot.java:150: '}' expected
- 11-17-2010, 02:40 PM #10
Java Code:import java.util.Random; class Slot { public static void main(String[] args) { Slot s = new Slot(); s.setCoin(20); s.compute(); } 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 double 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 * coin; return winnings; } public double getEuro() { euro = (coin * .25); return euro; } }
- 11-17-2010, 02:54 PM #11
Member
- Join Date
- Nov 2010
- Posts
- 7
- Rep Power
- 0
Thanks very much for that!! It sorted the problem it now actually works!! My next problem is getting the SlotMachine.java to work with it and then also add a loop to the program so it works!! Can you point me in the right direction please??
- 11-17-2010, 03:20 PM #12
Member
- Join Date
- Nov 2010
- Posts
- 7
- Rep Power
- 0
These are the errors im getting! Thanks for all the help so far begining to understand wer ive went wrong by looking at ur fixed code!! If you could help me with this last bit it would be great!!!
Am i missing any methods? I think this could be the problem!!Java Code:C:\Users\Andy\Desktop\Programming\SlotMachineApp.java:55: cannot find symbol symbol : method compute() location: class SlotMachine mySlot.compute(); ^ C:\Users\Andy\Desktop\Programming\SlotMachineApp.java:94: cannot find symbol symbol : method getWinnings() location: class SlotMachine Winnings = mySlot.getWinnings(); ^ C:\Users\Andy\Desktop\Programming\SlotMachineApp.java:97: cannot find symbol symbol : method getEuro() location: class SlotMachine Euro = mySlot.getEuro(); ^
Similar Threads
-
Project in Virtual Machine
By alex1970 in forum IntelliJ IDEAReplies: 0Last Post: 10-16-2009, 12:50 PM -
32 bit machine or 64 bit machine
By Kapil Gupta in forum Advanced JavaReplies: 13Last Post: 06-24-2008, 03:29 AM -
How to get URL from network machine
By Mir in forum NetworkingReplies: 1Last Post: 04-02-2008, 12:08 AM -
Getting name/ip of a machine
By Java Tip in forum Java TipReplies: 0Last Post: 03-02-2008, 07:11 PM -
Communication with Expansion Slot Compact Flash device on PDA
By percivalwcy in forum CLDC and MIDPReplies: 0Last Post: 07-25-2007, 09:04 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks