Slot Machine - Exception In Thread InputMismatchException (runtime Error)

Nov 16, 2014

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;

[Code] .....

View Replies


ADVERTISEMENT

Baby Names Exception In Thread InputMismatchException

Feb 10, 2015

I'm working on an assignment for my java class and I am currently stuck with an error/exception,

Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:864)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at BabyNames.search(BabyNames.java:45)
at BabyNames.main(BabyNames.java:20)

I input my name, which is able to get my name from the names.txt, however after that, it hits an exception and does not go further on.Also please use the names,

JIMMY
JIMMIE
JIMMU
JIMI
(All can be lowered case), because I am unable to upload the full file for it is very big.

import java.util.*;
import java.awt.*;
import java.io.*;

//Jimmy
//Programming Assignment #6: Baby Names
//This program is going to scan a file with data
//about names and their popularity starting from the 1890's
//and will display their popularity over the years in 10 intervals.

[code]...

View Replies View Related

How To Fix Logic Error For Slot Machine Game

Jan 2, 2015

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);

[code]....

View Replies View Related

JCreator Slot Machine

May 18, 2014

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) {

int count = 0;
while (count<3)

[code]....

View Replies View Related

Slot Machine Program Using Methods And Arrays

Nov 13, 2014

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
{

[Code]......

View Replies View Related

Swing/AWT/SWT :: Slot Machine - GUI Exit Button

Mar 13, 2014

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");

[Code] .....

View Replies View Related

Methods And Arrays Slot Machine Program Won't Compile

Nov 19, 2014

Here are the errors I am getting:

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?

[code]....

View Replies View Related

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

[Code] ....

View Replies View Related

JavaFX :: Slot Machine In Netbeans - Scene / Stage

Oct 21, 2014

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++)

[Code] ....

Button "SPIN" is created in createbottom();.

View Replies View Related

Getting RunTime Exception ClassCastException

Feb 28, 2014

i am getting runtime Exception Saying classCastException .here is my code where i am getting classcastException.

public class ModifyDetailsServlet extends HttpServlet {
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub

[code]....

View Replies View Related

Converting String To Number - Runtime Exception

Feb 6, 2014

I am getting run time Exception while converting String to Number....

public int convertToNumber(String numstr) {
int i = Integer.parseInt(numstr);
return i;
}

Here i am calling above Method convertToNumber().

if (validate.hasNumber(req.getParameter(LRSConstant.MOB_NUM))) {
bean.setMobno(ValidateUtils.getInstance().convertToNumber(
req.getParameter(LRSConstant.MOB_NUM)));
}

This is an Exception which i am getting at Run time

java.lang.NumberFormatException: For input string: "9700636702"
java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
java.lang.Integer.parseInt(Integer.java:461)
java.lang.Integer.parseInt(Integer.java:499)

[Code] ....

View Replies View Related

Converting String To Date Object - Runtime Exception

Jan 26, 2014

I am getting Run time Exception while converting String object to Date Object ....

java.text.SimpleDateFormat@b9b195a0
java.text.ParseException: Unparseable date: "14-07-2012"
public static void main(String[] args) {
String time = "14-07-2012";

[Code] .....

View Replies View Related

Exception In Thread Main

Jan 11, 2014

I am new to java and still learning. I am trying to execute the code below which compiles successfully, but getting the following error:"Exception in thread "main" java.lang.NoSuchMethodError: main"

Code:

class Dog{
int size;
String name;
String breed;
void bark(){
System.out.println("woof woof");
}
}
class DogTestDrive{

[code]....

View Replies View Related

Virtual Machine Launcher - Java Exception Has Occurred

Apr 29, 2014

I developed a Java application and it works fine on my computer, but when i tried it on another computers, I have the following errors :

A window named Java Virtual Machine Launcher appears and it says "A Java Exception has occured".

My application don't even launch.

Here is the error lines, but I don't know what to do :

C:UsersAdministrateur_localserveurtimet>java -jar ServeurTimeT.jar
Exception in thread "main" java.lang.UnsupportedClassVersionError: TimeTracking/
ServeurTimeT : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)

[Code] ....

Java is up to date.

View Replies View Related

Thread And Passing Exception With Two Classes

Jan 23, 2014

I have two classes, where main class is simple with only main function in it. Another class extends Thread and there's couple of functions I want to execute from main class.

Problem: I try to get other.shut() to be run in main class catch() block, after I have stopped the other class's running thread (e.g. by ctrl+c).

I think I need to somehow "pass" the exception from other class to main class so it goes to the catch block?

Code for main class:

Java Code:

public class MainClass {
public static void main(String[] arguments) {
OtherClass other = new OtherClass();
try {
other.exec();
} catch (Exception e) {
other.shut();

[Code] .....

View Replies View Related

Splitting String Not Working - Exception In Thread

Jul 19, 2014

I am designing the game of Snake but it crashes after i added the checkScore() method.

package com.complex.snake;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.*;
import javax.swing.JOptionPane;

[Code] .....

The error i get is : Exception in thread "Thread-3" java.lang.ArrayIndexOutOfBoundsException: 1

View Replies View Related

Exception In Main Thread - Class Introductions

Dec 26, 2014

import java.io.Console;
public class Introductions{
public static void main(String[] args){
Console console = System.console();
console.printf("Hello!My name is ---");
}
}

Output :-

Compiling Introductions.java.......
-----------OUTPUT-----------
Exception in thread "main" java.lang.NullPointerException
at Introductions.main(Introductions.java:5)
[Finished in 2.2s with exit code 1]

View Replies View Related

Rainfall Programming - Exception In Main Thread

Sep 10, 2014

exception in thread main java.lang.nullpointerexception code 45 and code 116

the lines are highlighted and no the code tags did not show up when I uploaded the file.

I typed '[code]' below:
Java Code: /**
This program demostrates rainfall for a year
*/

[Code].....

View Replies View Related

Exception In Thread - Array Index Out Of Bounds

Mar 20, 2015

The following code generates an array out of bounds exception

int[] myArray1 = new int[5]; 
for(int j = 0; j < myArray1.length; j++)
{
myArray1[j] = 10;
System.out.println("myArray1["+j+"] : " + myArray1[j]);
}
for (int i : myArray1) {
System.out.println("Blah myArray1["+i+"] : " + myArray1[i]);
}

The exception

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10
at Tutorial2.main(Tutorial2.java:40)

View Replies View Related

Eclipse IDE - 2 Classes And Exception In Thread Main

Aug 31, 2014

I use Eclipse IDE

public class Emp {
 private String name;
private String jobTitle;
 public void setName(String nameIn){
name=nameIn;

[Code] ....

<terminated> TestClass
Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Unknown Source)
at TestClass.payOneEmp(TestClass.java:21)
at TestClass.main(TestClass.java:13)

View Replies View Related

Exception In Thread Main - Cannot Format Given Object

Apr 16, 2014

I am working on a program that will allow a user to input grades for a class of four students who have taken two tests. Based on the grades entered, the program will calculate the averages of the two tests for each student and display it along with their respected letter grades.

Now I can get the program to compile successfully, but after inputting the grades in, I get the error message saying that it cannot format given object as a number. I am using 4 arrays to execute this program and maybe that's why I'm having the trouble? I'm not sure because I am still fairly new at this stuff and can't sen to resolve it.

I was having problems for a while and then finally got excited when I got it to compile without any errors and now I'm getting an error inside my program. All I need to do is format the numbers of the grades into something like: 000, and each of the averages as 000.0. I understand how to do it because I have done it in another program I've done in the past. I just don't know how to fix this error that is coming up.

here is my code:

import java.util.Scanner;
import java.text.DecimalFormat;
public class TestAverage
{
/**
* A program that will store and process 2 test scores for a class of 4 students.
* The program will prompt for the test scores as shown above in the sample run.
* After all the data is entered,the program will display the score for test 1, test 2 .
* The average of the 2 tests and the letter grade for the class for each student in a tabular format.
*
*

[code]....

View Replies View Related

Thread Java - Illegal State Monitor Exception

May 30, 2014

Class A{
Public static synchronized void main(String args[]){
Thread t= new thread();
t.start();
Sysout("hi");
t.wait(1000);
Sysout("hello");
}}

Illegal state monitor exception. Why?

View Replies View Related

Runtime Error On View Contacts

Feb 9, 2015

why get a runtime error when choosing option 2 after adding a contact?

Main:

package contactlist;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

[code]....

View Replies View Related

Runtime Error In Package Program

Jan 20, 2015

Iam getting this error at run time while using this command "java mypack.Accountbalance". I have compiled this source code and got its class file that I have put in mypack package but now its showing this error ..

Here's the code :
package mypack;
class Balance
{
String name;
double bal;
Balance(String n ,double b)

[Code] .....

Error:
exception in thread "main" java.lang.NoClassDefFoundError: mypack/Ba
at mypack.Accountbalance.main(Accountbalance.java:25)
used by: java.lang.ClassNotFoundException: mypack.Balance

View Replies View Related

Runtime Error With DB Table Generator File

Oct 14, 2014

I am having some issues with this code its a a DB generator that creates tables and populates them. There seems to be no compiler errors, but there is a runtime error. I have added the error and the code below :

Runtime error:

Exception in thread "main" java.sql.SQLException: [Microsoft][ODBC Driver Manager]
Data source name not found and no default driver specified
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6964)

[Code] .....

My Code:

MakeDB.java
import java.sql.*;
import java.io.*;
public class MakeDB {
public static void main(String[]args) throws Exception {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

[Code] .....

View Replies View Related

How To Make Difference Between Compilation Fails And Runtime Error

May 5, 2014

I want to know if there is any general rule/pattern about things which give compilation fails and things which go for Runtime error/exception. OR only way is to remember all of them and there is no actual pattern in it.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved