Slot Machine - How To Calculate Winnings And To Spin Again / Exit
Nov 22, 2014
Working with the winnings and how to spin again or exit.
import java.util.*;
class Wksht5Q1{
public static void main(String[] args){
Scanner in = new Scanner(System.in);//For user input
Random rand = new Random();//For number generator
//Variables for user input
I've spent ages trying to implement an exit button into this code. Its the start of a GUI for a slot machine, the actual machine code is in a separate class and I haven't linked them yet. My question is where/how would the exit button be added? I've tried and failed a lot of times....
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class SlotMachineGUI { public static void main (String[] args) { //create new jframe JFrame frame = new JFrame ("Slot Machine");
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) {
I am designing a program that generates 3 random numbers from 1-5 and if 2 match, the user wins $1. If 3 match, the user wins respectively:
All 1s - $5 2s - $10 3s - $25 4s - $50 5s - $100
I first used a loop to run until the user runs out of money or wishes to stop. Then I made 2 methods. 1 to generate the random numbers and 1 to see if the user won any money. I am storing the random numbers in an array called slotnumber.
This is what I have so far but I am getting compiling errors at while (cont == 'y') {
import java.util.Scanner; import java.util.Random; public class SlotMachine {
I'm trying to fix this logic error in my slot machine game where no matter what slot combo comes up, it says you have won $10 and proceeds to add that amount to the balance and subtract the bet amount to the balance, even though it is not a winning combo! I've been trying to solve that and when doing so, I commented out Slot1.randNum1 == 0, Slot2.randNum2 ==0, and Slot3.randNum3 ==0 and anything relating to see if that was the problem, and it seemed like it was, because after that, the logic error described above was gone, but in doing so, the loss/win counter didn't increment, nor did the program pick up on the winning combos. However, I do not know why commenting out anything relating to randNum ==0 would cause that.
Here is the code for the processing (as you can see, some parts are commented in attempt to fix the logic error, but right now the code below is for the logic error that keeps on telling that the user has won):
public void askData () { title (); int betAmount; while (true) { try { c.setCursor (3, 1);
SlotMachine.java:21: error: illegal start of expression public static void getNums(int [] slots) ^ SlotMachine.java:21: error: illegal start of expression public static void getNums(int [] slots)
[code]....
i keep fixing small things and cannot get it to compile. Below is the original code,
import java.util.Scanner; import java.util.Random; public class SlotMachine { public static void main (String args[]) { int userMoney; Scanner input = new Scanner(System.in); System.out.print("How much money to start with?
I want to create a slot machine in NetBeans, with JavaFX library (without using JavaFX Scene Builder) but i have some problems to create UI.
I created algorithm already but without visuals.
Now my code is:
public class BEST extends Application { private ImageView var; //init imageview of images public static void main(String[] args) { launch(args);
[Code] ....
createbottom(); and creategr(); i wrote already (and my program creates grid pane of random images with double dimension array, random and imageview) and program runs, but i don t know how to keep track of credits balance,in the same time to create new random gridpane of images and to get rid of every gridpane.
Here is creategr();
private GridPane creategr(){ final GridPane creategr = new GridPane(); int[][] newarray=new int[3][3]; int w=100; for(int i=0; i<3; i++){ for(int j=0; j<3;j++)
For this program, I have to run a slot machine. It runs until right before the do while loop and then I receive the error: Exception in thread "main" java.util.InputMismatch.Exception. Searching around, someone said it was a scanner error and adding a call keyboard.nextLine(); fixes the problem- however with that I receive the same error.
Code : import java.util.Scanner; import java.util.Random; import java.io.*; public class SlotMachineSimulation { public static void main(String[] args) throws IOException { int number;
I have developed a code to connecting remote windows M/C from local M/C by using SSH2 (ganymed-ssh2-build209.jar) API. when I run the code its giving below error. Is there any other way to connect remote windows system using java code.
Exception.
java.io.IOException: There was a problem while talking to <host name>:22 at ch.ethz.ssh2.Connection.connect(Connection.java:642) at ch.ethz.ssh2.Connection.connect(Connection.java:460) at Connect.RemoteServer.ConnectWindowsServer.runCommand(ConnectWindowsServer.java:55) at Connect.RemoteServer.ConnectWindowsServer.main(ConnectWindowsServer.java:27) Caused by: java.net.ConnectException: Connection refused: connect
I have a requirement where I have to send a file from a local system to unix box(present on client side) using java code.I have developed a code that is successfully sending the file from local system to client side unix box (I am connecting to client side unix box using VPN) provided I run the code in my eclipse IDE present in local system. But when I am running the same code in the unix box it is throwing null pointer exception.Might be the unix system is not recognising the local system. Please find the code.
what I needed to know to complete the lesson, but now it just tells me what the output should be and I have to research the information on my own. anyways, here is my code from the previous lesson:
import java.util.Random; import java.util.Scanner; public class tnArray { public static void main(String[] args) { int [] array;
[code]....
Now I have to change it so that instead of counting the number of times a number will appear in the array, I must output which slot in the array the number is in.
I just want to know how I can get my program to end when the user inputs "0." By using: System.exit(0);
import java.util.Scanner; public class TestCode { public static void main (String [ ]args ) { Scanner console =new Scanner(System.in); System.out.println("To exit program input 0"); for (int y = 1; y < 11; y++ ){ // Executes output 10 times
import java.util.Scanner; // program uses Class Scanner import javax.swing.JOptionPane; public class ModCalculator { // main method begins execution of Java application
[code]....
I am having troubles with allowing the user to input operations/digits until they want to exit, I have tried looping, but I was unsuccessful, came here hoping to figure this out.Currently I have it ending with Break statements after each switch so that they don't coincide all together.. I can't figure out how to keep the Break statement AND loop to previous code of System.out.println( "Please enter an operand which you would like me to calculate with :");
String st = input.next(); c = st.charAt(0); System.out.println( "I will need for you to input two integers and I will output the result."); System.out.print( "Enter first integer to calculate: " ); // prompt number1 = input.nextInt(); // read first number from user System.out.print( "Enter second integer to calculate: " ); // prompt number2 = input.nextInt(); // read second number from user
and allowing it to run through the rest of the program with the options still in tact, while having an if statement of an exit keyword.
I have been going over my code line by line, over and over again for nearly and hour now...When I execute method `file.createNewFile()`, the method returns true and throws no exceptions. It even says that the file exists. However, the file is not created and cannot be accessed until the program has exited.
File portLib = new File(""); private class RememberPortAction extends AbstractMenuItemAction { methods... protected void actionPerformed() { LibraryCreator creator = new LibraryCreator(self, logger); File newPortLib;
Description of the program: read a sequence of positive integers from terminal. When user types
-1, the program will print out the largest number and exit.
Program mid.java import java.util.Scanner; public class test { public static int num; public static void main (String[] args) { Scanner in = new Scanner(System.in); num = in.nextInt(); int large = num; while(num > 0); { if(0 > num && num > large) large = num; } System.out.println("The largest number is : " + large); } }
I am submitting on a online judge. I am getting NZEC exception in my code
this is my code
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class MyProgram { static int[] arr; static int sum=0; static int x,y,N;
import java.util.ArrayList; import java.util.Scanner; public class Main { private String[] inputStrings; private ArrayList<InputField> decodedMessage; public static void main(String[] args) throws Exception{ new Main().solve();
[Code] ....
This is giving me NZEC exception.I am testing this solution on a online judge.So I don't have any TestCase in which this is failing. So, what are the possible reason of NZEC exception in my code?
This is my first java program,i am using eclipse IDE-----
package day1.example;
public class MyFirstJava {
/** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("hi"); } }
When i saved it,it shows no error.when i run it then a pop-up says "could not find the main class.the program will exit" and in the console it says---
java.lang.UnsupportedClassVersionError: day1/example/MyFirstJava : Unsupported major.minor version 51.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.access$000(Unknown Source)
My question is how can I make the program repeat until the user enters the number 4 to exit?
/** * Write an application for a furniture company; the program determines the price of a table. Ask the user to choose 1 for pine, 2 for oak, or 3 for mahogany. The output is the name of the wood chosen as well as the price of the table. Pine table cost $100, oak tables cost $225, and mahogany table cost $310. Also ask the user to specify a
(1) large table or a (2) small table.
Add $35 to the price of any large table and add nothing to the price for a small table. Display the output. Your program must repeat until the user chooses to exit.
*/ import java.util.Scanner; public class Wood { public static void main(String[] args) { Scanner input = new Scanner (System.in); System.out.println ("Table Prices");
I have a Single Frame Application and I simply want to prompt the user with a dialog confirming they really want to close before they actually close the program, specifically when they click the X in the upper right. I THOUGHT it was like any other java application, with the slight added complexity of having to target the program-created-JFrame with: ".getApplication().getMainFrame()".
With that code, DO_NOTHING_ON_CLOSE is set on the JFrame, yet the program closes anyways. Which I don't understand.So I did some reading and found this: URL....That lead me to the configureWindow override, where I successfully tried this:
root.addWindowListener(new WindowAdapter() {
@Override public void windowClosing(WindowEvent e) { // write your code here System.out.println("Window Closing"); } });
But as far as I can tell that will only let me react to the window closing, not to the command to close it, where I could then kill the command in the dialog if they so "no I'm not ready to quit yet", if that makes sense. So, how to give a prompt before closing?I am using netbeans IDE to create this app - not sure if that is relevant, since maybe it is an oddity with the IDE and not Single Frame Applications.
My homework assignment is: Using a do-while statement, write a Java program that continuously requests a grade to be entered. If the grade is less than 0 or greater than 100, your program should display an appropriate message informing the user that an invalid grade has been entered; a valid grade should be added to a total. When a grade of 999 is entered, the program should exit the repetition loop and compute and display the average of the valid grades entered. Run the program on your computer and verify the program using appropriate test data.
When I run it, I don't get the correct average. I know that i'm supposed to enter 999 to exit the loop and to display the average, but 999 is being added with the loop. I'm not sure how to make it not do that.
//stephanie import java.util.Scanner; public class gradeAverage { public static void main(String[] args)
In my JSF application user starts on primary server where the session begins and then the user is redirected to a different server using sendRedirect. I want to pass some authentication token to the next server from primary server. I am trying to set session attribute as:
But this attribute is not reaching the new server. I cannot pass this auth_token as request parameter as that wont be secure. So how to get some session data to new server?
My output is all over the place. I cancelled out the borderlayouts beneath each panel I created and it completely changed the output, and I'm not sure why. The first photo below, shows what it looked like with the layouts and the second shows the output without. I still don't understand why I don't see the digits 1-9.
Java Code:
import javax.swing.*; import java.awt.*; import java.awt.event.ActionListener; public class Atm extends JFrame { Atm(){ super("ATM"); //Create Panels For ATM JPanel buttonPanel1 = new JPanel(); //To Contain Digits 1-9
[Code] ....
Why would setting the layout beneath each object change the layout so much? I stayed consistent in my use of BLayout and GLayout in the program.