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.