ArrayIndexOutOfBoundsException In Lottery Application
Jul 25, 2014
I have tried changing the bounds of the arrays but I still don't see where the exception is occurring or how to resolve this issue. Am I missing something blatantly obvious? Below are the two class files for the lottery application that I've been working on for a school assignment.
package com.lottery.test;
import com.lottery.Alarcon.*;
import java.util.Scanner;
public class PlayLottery {
public static void main(String [] args){
System.out.println("CIS-132. Lab 8. Problem #9 - Lottery. Faber Alarcon.");
Lottery lottery = new Lottery();
[Code] ....
I forgot to post the error message I was getting, here it is.
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
at com.lottery.Alarcon.Lottery.compareNumbers(Lottery.java:26)
at com.lottery.test.PlayLottery.main(PlayLottery.java:27)
Java Result: 1
I am writing a java application that will function as a lottery game, using arrays it prompts the user to enter 5 digits and matches them against the random lottery numbers generated.
import java.util.Random; import java.util.Scanner; public class App { public static void main(String[] args) { int NUM_DIGITS = 5;
Got the gui to run but the program fails after the first or second loop. It seems to not being able to find the next move with out moving off the board. This is my output on the command line
8 8 8 8 8 8 8 8 NNE NEE SEE SSE SSW SWW NWW NNW java.awt.Point[x=1,y=3] Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1 at ktdemo.KnightsTour.nextMove(KnightsTour.java:220) at ktdemo.KnightsTour.nextMove(KnightsTour.java:240) at ktdemo.KnightsTour.nextMove(KnightsTour.java:240) at ktdemo.KnightsTour.findSolution(KnightsTour.java:203) at ktdemo.KnightsTour.access$800(KnightsTour.java:20) at ktdemo.KnightsTour$StartTourListener.mousePressed(KnightsTour.java:162) at java.awt.Component.processMouseEvent(Component.java:6502) at javax.swing.JComponent.processMouseEvent(JComponent.java:3320)
/** * In this program, use for and while loops with calculations to get the lottery odds. */ import java.util.Scanner; import java.util.Random; public class Lottery { public static void main (String []args)
[Code] .....
I need getting my numbers matching. When, I run the program each time no matter what number it keeps saying sorry no matches. However, I do need the program to have matches.
I wrote the following code for a lottery game. The problem comes when I run it. If one number of a 3 digit number matches, it's supposed to print "you win 1000" But regardless if a number matches or not, it says "sorry, no matches" ...
import java.util.Scanner; public class Lottery { public static void main(String[] args){ //generate lottery number int lottery = (int)(Math.random() * 1000); //Prompt the user to enter numbers Scanner input = new Scanner (System.in); System.out.print("Enter your numbers (3 digits): "); int guess = input.nextInt();
import java.util.Scanner; import java.util.Arrays; public class LotteryTester { public static void main(String[] args) { LotteryApplication lottery = new LotteryApplication(); int lotteryNumbersCount = lottery.getLotteryNumbers().length;
[Code] ....
Everything works fine but when I run it the matching numbers tends to be off. For example I will type Enter in 1,1,1,1,1 for my 5 numbers. The lottery numbers will be 5,3,4,5,8 and it will say 1 number matched.
I have problem with sorting my numbers from smallest to biggest and i need to not have repeating numbers, I am stuck. I tried using Arrays.sorts(lottery) but didn't work. and i don't know to but make the numbers not repeat in the same line.
package lottonumbers;
public class LottoNumbers { public static void main(String[] args) { int[] lottery = new int[6]; for (int numoftimes=0;numoftimes<5;numoftimes++){
Write a Java program that randomly generates a five-digit lottery number and prompts the user to enter a five-digit number. Each digit in the number is in the range between 0~9. The program should determine which prize the user wins according to the following rule:
• The user wins the first prize if the user input matches all five digits in the lottery number in exact order. • The user wins the second prize if the user input matches any four digits in the lottery number in exact positions. • The user wins the third prize if the user input matches any three digits in the lottery number in its exact position. • The user wins the fourth prize if the user input matches any two digits in the lottery number in its exact position. • The user wins the fifth prize if the user input matches any one digit in the lottery number in its exact position.
and here is my code. I cant get it to print the right statements.
import java.util.Scanner; import java.util.Random; class Hw5 { static int getPrize(int g1, int g2, int g3, int g4, int g5, int u1, int u2, int u3, int u4, int u5) { //code for determining the prize comparing (g1, g2, g3, g4, g5) to (u1, u2, u3, u4, u5) if (u1 == g1 && u2 == g2 && u3 == g3 && u4 == g4 && u5 == g5)
convert or move standalone java thread application into Tomcat server container for accessing its JNDI services? Also is it possible to schedule this thread application in Tomcat server? is it possible to keep this app in tomcat as web application and schedule in window's scheduler.
I am new to work on JNLP program. I have created a SWING program, JNLP file when i deploy the ear file i am getting 404 error. Please find the steps in details.
1.Created a dynamic web project JWStartProject in eclipse
2.Create a HelloWorld.java class under default package.
import javax.swing.*; public class HelloWorld extends JFrame { private static final long serialVersionUID = 4968624166243565348L; private JLabel label = new JLabel("Hello Java Web START!"); public HelloWorld() { super("Jave Web Start Example"); this.setSize(350, 200); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE ); this.setLayout(null);
[Code] ....
Now I exported this project as JWStartProject.war contains following code.
Created Server in Websphere Admin console
Deployed this war file under the server and started.
I have added MIME types also.
I am unable to launch the application. I am getting 404 errors. May I know where I went wrong?
I want to know the how to refresh the jsf application after doing something like Faceboook... i.e if i comment or post in my application so automatically the whole application have refresh.
A while ago, I developed an application in VB.net, and I'm trying to "convert" this application to Java. But this VB.net application uses some specific DLLs and I need to use them in my Java application. However, my knowledge in this respect are quite limited in manupulate DLLs on Java.
Up to this point, I can already load the DLL. I've read some documentation on how to use functions that are in the DLL; but I have some doubts. For example, how can I translate this piece of code to Java?
Java Code:
API = New MyDLL.Base With API .para1= "1" .para2= 2 .para3= True .para4= False
I am currently faced with a task of creating a web application. This application is meant to be accessed by an admin and also a customer. On the customer side the app should prompt the user to fill in an application for of sort and also allow the user to upload a CV to a database. The information entered by the customer will also be saved on the database. The admin should have the ability to look through all the candidates and their information and CV`s. He should also be allowed to search for candidates with specific key words...I am not a professional programmer but know the core of Java programming. I have a tiny bit of knowledge of MySql.
I am working on an app that would require an activation code in order to be used after being downloaded (user will get teh code from me) am using Java pro.
I want to monitor performance of web application, running in java JVM(Java version 1.5.0_22) using tomcat web server, for a given functionality want to find, methods and sql queries how much time taking for execution. i am looking for setting and free tools available.
Say I have a EAR file. Inside, it has a EJB jar, web war and app client jar file. The (enterprise) app client here is a desktop GUI calling the EJBs accordingly. Now if this EAR is deployed to some app server like JBoss or Glassfish, to access the app client, users will basically use java web start/ JNLP to run the client.
Given this is the case, I'm wondering if the effect is the same as separating the app client (not part of the EAR), have that EJB jar in its library path, and deploy the GUI app as a jar. Hence users not use web start. The only disadvantage I can think for separating the app client is if the EJBs get changed, the client's version will be outdated. But other than that, are there any justification for using an enterprise app client?
So say I write up a program like a dice roll game, which I see on the forums here. It's all written and good to go and when I hit Run it does what I want it to do, no errors..What do I do with those .class and .java files? Do I compile it somehow into an app I can put on the google play store? What is the NEXT STEP after the program is all written?
I'm having trouble doing out a class diagram for an app I'm trying to create.The app is a quiz app for students to use in their study. The following objects I have to put in the class diagram are:
Basic Questions attributes: questionText correctAnswer mark (representing the mark awarded for a correct answer) Answer (representing the answer entered by the user).
Multiple choice question attributes: questionText correctAnswer mark (representing the mark awarded for a correct answer) option a, option b and option c (representing each of the possible answer) answer (representing the answer chosen by the user)
Essay Question attributes: questionText correctAnswer mark (representing the mark awarded for a correct answer) answer (representing the text entered by the user) maxWordCount (representing the maximum word count for the essay)
Picture Question attributes: questionText correctAnswer answer (representing the text entered by the user) imageName (representing the image to be displayed with the question)
I am writing a Java Swing GUI application on my pc. I have to give this application to my cousin with another pc, where he is not aware of programming. then how can he execute that application? are there any ways of skipping the "javac" and "java" procedures while executing the app on his computer?
I am using win7 x86 and same at my cousin's place. I am also using eclipse-kepler sr1 ide for app development.
Are there any easy ways of automating this "javac" and "java" process(compilation and execution)? something like...scripting?