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.
SlotMachine.java: implements the Slot machine logic Gambler.java: represents the Slot machine player SlotsTest.java: class used to test implementation of SlotMachine data directory: directory containing machine and gambler datafiles. You will add new datafiles while testing your SlotMachine.
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.Slot Machine Simulation Java
C:UsersAndyDesktopProgrammingSlotMachine.java :55: cannot find symbolsymbol : method compute()
location: class SlotMachine
mySlot.compute();
^
Slot Machine Programming Code
C:UsersAndyDesktopProgrammingSlotMachine.java :94: cannot find symbol
symbol : method getwinnings()
location: class SlotMachine
winnings = mySlot.getwinnings();
^
C:UsersAndyDesktopProgrammingSlotMachine.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');
}
}
1.C:UsersAndyDesktopProgrammingSlot.java:44: illegal start of expression
public void setCoin(int c){
^
2.C:UsersAndyDesktopProgrammingSlot.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;
}
Thanks for taking the time to read this.
Introduction
- We have summarized how to create a Java project using Eclipse.
Operating environment
- Windows 10(64bit)
- OpenJDK 11
- Eclipse IDE for Java Developers(Version: 2020-06)
Development environment construction ①: OpenJDK 11 installation
JRE (Java Runtime Environment) is required to run Eclipse. Here, download OpenJDK to get the JRE. If you do not have JRE installed, you will get an error when starting Eclipse, so you need to do it before installing Eclipse.
Go to the official OpenJDK website below and click the
jdk.java.net/14
link in the Download section. (The link forjdk.java.net/14
changes every time OpenJDK is upgraded.)https://openjdk.java.net/Click Java SE 11 in the list of links on the left. (If you want to download the latest version of OpenJDK, you can download OpenJDK from this site.)https://jdk.java.net/14/
Click Windows / x64 Java Development Kit.https://jdk.java.net/java-se-ri/11
'openjdk-11 + 28_windows-x64_bin.zip' will be downloaded.
When the download is complete, unzip it to any folder and add the absolute path of 'jdk-11 bin' to your system environment variables. (Here, I unzipped it to C: openjdk and added 'C: openjdk jdk-11 bin' to the system environment variables.)
Start a command prompt and check the Java version. (If it is openjdk 11, it is OK.)
Development environment construction (2): Eclipse installation
After the OpneJDK installation is complete, install Eclipse.
Go to the Eclipse package installer download site and click 'Windows 64-bit' in the 'Eclipse IDE for Java Developers'.https://www.eclipse.org/downloads/packages/
When you are on the download page, click the Download button.
eclipse-java-2020-06-R-win32-x86_64.zip will be downloaded.
When the download is complete, unzip it to any folder and double-click 'eclipse.exe'. (You will be required to enter the workspace folder path at startup, but leave the default settings.)
Eclipse initial settings
Initialize Eclipse before creating a project. If you set it once at the beginning, you do not need to set it from the next time.
Execute the main menu 'Window'> 'Preferences' to launch the 'Preferences' dialog.
Select Java> Installed JREs from the tree on the left and make sure the OpenJDK 11 path is set.
Set the character code. Here, we will change it for Linux assuming that it will also work on Linux. Select 'General'> 'Workspace' from the tree on the left, check 'Other' in 'Text file encoding', and select 'UTF-8'. Also, check 'Other' in 'New text file line delimiter', select 'Unix', and press the 'Apply' button.
Change the font to prevent garbled characters. Select 'General'> 'Appearance'> 'Colors and Fonts' from the tree on the left, select 'Java Editor Text-Font', and press the 'Edit' button to launch the 'Fonts' dialog. Change the font in the 'Font' dialog and press the 'Apply' button. (Here, I changed to MS Gothic. Depending on the font you select, the characters may be garbled, so select a font that does not garble.)
Press the Apply and Close button.
Project creation
First, create a project.
Click File> New> Java Project on the main menu to launch the New Java Project dialog.
Enter the project name in the 'Project name' field and press the 'Finish' button. (Here, the project name is 'sample' and other settings are left as default.)
When the 'New module-info.java' dialog is launched, press the 'Don't Create' button.
Confirm that the sample project tree has been generated on 'Package Explorer'.
Create main class
Next, create the main class (the class that contains the main method).
Select the top node of the tree on 'Package Explorer', right-click and click the pop-up menu 'New'> 'Class' to launch the 'New Java Class' dialog.
Enter the class name in the 'Name' field, check 'public static void main (String [] args)', and click the 'Finish' button. (Here, enter 'SampleMain' in the 'Name' field.)
The 'sample'> 'src'> 'sample'> 'SampleMain.java' node is added to the tree on 'Package Explorer'. The code for SampleMain.java looks like this:
Add any code to the source code of SampleMain.java.
System.out.println ('Hello'); // AddSystem.out.println ( 'Hello'); // add}
Build
For builds, enable automatic builds so that they build automatically.
Select the top node of the tree on 'Package Explorer', right-click and click the pop-up menu 'Reflesh' to automatically update the file structure of the tree on 'Package Explorer' to the current state. ..
Check 'Project'> 'Build Automatically' in the main menu to enable automatic build. (If the build is not executed, click 'Project'> 'Clean' in the main menu.)
Run
Run it when you have a build.
Click Run> Run Configurations on the main menu.
Double-click Java Application in the tree of the Run Configurations dialog to add the child node New_Configuration.
Change the 'Name' field to the main class name 'SampleMain' and press the 'Apply' button to update the child node 'New_Configuration' to 'SampleMain'.
Open the 'Main' tab, enter the project name in the 'Project' field and the class name including the main method in the 'Main class' field, and press the 'Apply' button.
Press the Run button in the Run Configurations dialog, or press the Run button on the icon.
In the 'Console' window, you will see 'Hello Hello'.
debug
If you want to debug, do the following:
Click Run> Debug Configurations on the main menu.
Double-click Java Application in the tree of the Debug Configurations dialog to add a child node New_Configuration.
Change the 'Name' field to the main class name 'SampleMain' and press the 'Apply' button to update the child node 'New_Configuration' to 'SampleMain'.
Open the 'Main' tab, enter the project name in the 'Project' field and the class name including the main method in the 'Main class' field, check 'Stop in main' and press the 'Apply' button. ..
Press the 'Debug' button in the tree of the 'Debug Configurations' dialog or the 'Debug' button on the icon to start debugging.
Since we have checked 'Stop in main', we will break at the beginning of the main method.
Set a breakpoint with Ctrl + Shift + b and press F8 (Run) to break at the location where you set the breakpoint. You can also step in with the F5 key and step out with the F6 key.
Recommended Posts