Lotto Game - Receive Integer And Check If Int Was Not Entered Before

Nov 29, 2014

We were given the assignment to program a lotto game. in our game we should do follow the following steps below, and we are supposed to use atleast tree methods. the first one to receive the array of integers and an integer and check if the int was not entered before. the user should not repeat the same number. the other method will draw all numbers of a game (quantity of numbers to draw is based on the number parameter) and returns them in an array. the last method will display the result of the game. It receives a list of all lines played and a list of all numbers draw.

these are the steps to follow:

1. Ask the user how many lines (games) the user would like to play. Each line is made of five numbers between 1 and 45 (inclusive).

2. Ask the user to enter five numbers between 1 and 45 (inclusive) for each line. The user must NOT be allowed to enter a number more than once for each line.

3. When all the numbers for all the lines are entered, the program should display all lines and asks the user to confirm the game. If the user does NOT confirm the game, the program should start all over again.

4. Draw (generate) five numbers between 1 and 45 (inclusive). The numbers should be unique within the draw.

5. Draw (generate) one number (the bonus number) between 1 and 45 (inclusive). The number should be unique within the draw.

6. Display all the lines played and the result of each line.

7. Ask the user if the person would like to play again, if so the program should start the process all over again.

View Replies


ADVERTISEMENT

Check If Lotto Number Has Been Or Not In Last Week

Nov 25, 2014

I need to check numbers from 1-39 and see if the number has been or has not been a winning number in the last week lottery. How to do that?

This is code for random number, 7 numbers

import java.util.ArrayList;
import java.util.Random;
public class Loto {
public static void main(String[] arg) {
ArrayList<Integer> al = new ArrayList<Integer>();
for(int i = 1; i <= 39; i++)

[Code] ....

View Replies View Related

Check If Letter Entered By User Matches The One In Array

Jun 10, 2014

/**
* Auto Generated Java Class.
*/
import java.util.*;
public class Hangman {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
int guess;
boolean revealed[] = {false, false, false, false, false};
String word [] = {"c", "a", "n", "a", "d", "a"};

[Code] ....

I am not sure how to make the program check if the letter entered by the user matches the one in the array. also i am not sure how to make the program run again with a new word.

View Replies View Related

Read Integer From Keyboard Until Negative Number Is Entered

Apr 8, 2014

Basically i have a question ask me to write a program that read integer from keyboard until a negative number is entered, and then print out the max and min out of the number i have entered.

This is what i have done already which works, but i need to ignore the negative number when print out max and min...which i dont know how to do so. when i compile this program now it will always give me the negative number i enter at the end as minimum. which i need to ignore

Also if negative number is entered at once the program should print a error message say max and min are undefined.

public static void main(String[] args) {

Scanner in = new Scanner(System.in);
int large = Integer.MIN_VALUE;
int small = Integer.MAX_VALUE;
while(true) {
System.out.print("Enter a integer: ");
int n = in.nextInt();

[Code] ....

View Replies View Related

Input 10 Integer Numbers Into Array And Determine Maximum Value Entered

Apr 22, 2015

a. Write a Java program to input 10 integer numbers into an array named fmax and determine the maximum value entered. Your program should contain only one loop, and the maximum should be determined as array element values are being input. (Hint: Set the maximum equal to the first array element, which should be input before the loop used to input the remaining array values.)

b. Repeat 1a, keeping track of both the maximum element in the array and the index number for the maximum. After displaying the numbers, display these two messages:

The maximum value is: _________
This is element number __________ in the list of numbers

Have your program display the correct values in place of the underlines in the messages.

c. Repeat 1b, but have your program locate the minimum value of the data entered.

I did parts a and b but for part see i just want to know if i did it correctly or not

import java.util.Scanner;
public class MinimumValueArray {
public static void main(String[] args) {
//Variable Declaration
Scanner keyboard = new Scanner(System.in);
int size = 10;

[Code] ,.....

When I run it i get this The minimum value is 0.0

The element that holds the value is 0 right away. is this right for the minimum or am i supposed to enter values and it will display the minimum value like in parts a and b wit the maximum? will the minimum just always be 0 or ?

View Replies View Related

How To Check Input Is Integer In Java

Dec 18, 2014

I have to ask how many children's tickets you want to order. When I apply the code below, it just accepts whatever I input, including letters. I imagine it is to do with setting childrensTickets = 0? If I input a letter using the below it accepts - shouldn't it print the error given the input is not >=0?

System.out.print("How many children's tickets do you require? ");
int childrensTickets = 0;
boolean validChildrenValue = false;
while (validChildrenValue == false) {
if(aScanner.hasNextInt()) {

[Code] ....

View Replies View Related

Check User Input Is Integer

Dec 18, 2014

System.out.print("To begin, please enter 1 to choose stand tickets or 2 to choose terrace tickets for your party. ");
int standOrTerraceTickets = aScanner.nextInt();
while (standOrTerraceTickets != 1 && standOrTerraceTickets != 2)
{
System.out.print("Invalid input. Please enter 1 for stand tickets or 2 for terrace tickets. ");
standOrTerraceTickets = aScanner.nextInt();
}

Okay I thought I had this working properly so that when the user entered anything other than 1 or 2 they would keep getting an error invalid input, however, that only works when the user enters an integer. If the user enters anything other than a number, the program crashes. How does one prevent this from happening?

View Replies View Related

ESP Game - Cycle Through Colors After Each Guess Entered

Dec 16, 2014

I'm writing an ESP game code for class. The problem is i cant get it to cycle through the colors after each guess is entered. It stays fixed on the original random number generated.

import java.util.Random;
import java.util.Scanner;
public class Final1 {
String colorInput, computerColor;
int computerNum, right, wrong;

[Code] ....

This repeats 10x but the color never changes from the initial random chosen.

View Replies View Related

Prompt User For Integer To Make Sure Length Entered By User Is A Power Of 2

Oct 8, 2014

Basically I need to make a program prompts the user for an integer, check to make sure the length entered by the user is a power of 2 and at least 2. Then I need to convert from base e to base 2 then I need to print the tick marks of a ruler based of the value of the length.

I got the whole converting thing working and the check for a power of 2, that wasn't an issue because it didn't require any recursion. I just don't know how to print out the proper tick mark values.

The way it is supposed to work is that it needs to look like this. Say the user enters 8;

012131210
012345678

Or if the user enters 16;

01213121412131210
01234567890123456

The bottom row is pretty much just the index value, that I print fine.

The top row though is supposed to be the length of the ticks on a ruler, with the middle most value being the value of the conversion from base e to base 2 from above. I can get that printed and what I get just looks like this.

For 8;

000030000
012345678

For 16;

00000000400000000
01234567890123456

As you can see I can get the middle value and the index values below but I don't know how to use recursion to get the right numbers.

Here's my current code.

import java.util.*;
public class TickMarks {
public static void main (String args[]){
Scanner input = new Scanner(System.in);
boolean looping = true;
while(looping == true){
System.out.print("Please enter a length: ");

[Code]...

Now the methods isPowerOfTwo() and printLength() both work fine. However, I'm not sure how to get the left and right side working.

My thoughts were to split the length in half and get a left and right side. I gave both of them arrays so I can keep track of the values. Now as you've seen above I get all zeros and I know it's because that's the default value in an array, I just don't know how to get the proper values.

View Replies View Related

Translation Game - Translate A Word Proposed To And Check If Input Response Is Correct

Dec 19, 2013

The project is to develop the game Translate the Word .... It is asking user to translate a word proposed to and check if the input response is correct. At the end of the game score will be calculated and displayed.

Game Play :

1 - Ask the user to specify , through the console , its name and the number of words to offer . It is up to you to handle exceptions (eg number of words greater than the number you provided )
2 - Recover user response ( the word translated ) and check whether to continue . (eg you want to continue (y / n)) after each proposal.
3 - compare the response of the user with that which is preset for the word in question .
4 - Show the score at the end ( or at the breakpoint ) .
5 - Save the file in a user name , the score , the number of questions and the start date and end of the game played .

Some notes to consider :

1 - The language (eg, English - French , English - Arabic , etc. . ): It is up to you to specify the language adopted in the game and inform the user of your choice.
2 - The word bank to offer : It is up to you to develop the appropriate means to get the words to propose to the user. That said , the words and their translations can be retrieved :

a. a TXT file
b . an XML file . ( Tutorials DOM and SAX )
c . CSV file ( OpenCSV Tutorial )
d. a database ( Tutorial Access)
e . through APIs (eg Wordnet and google translate etc . ) .
f . a combination of the previous options a, bc , d and / or e . (eg words stored in a txt file and answers retrieved from the api google translate)
g . etc. .

Examples of files and databases are attached to the project statement . You will need to add one or more external libraries to your project. Click here for details on adding external libraries to Netbeans .

3 - A user will be associated with the question score if he can translate the word correctly. The score for each question can be calculated based on the number of words / questions to be proposed .

Development : In this project you will need at least a class called Question to encapsulate the word and its translations and provide all necessary methods to manipulate the object type Question.

An interface called IParser to make extensible project. Any class that implements IParser is a parser file (XML , TXT , CSV , etc.). / Database. In your project there will be a single class that implements IParser and will be used to retrieve words and their translations.

Add the ability to store the questions and answers of the user on the hard disk. Make the class Serializable Question

View Replies View Related

Word Game (how To Check That Word Is In Dictionary)

Apr 21, 2014

import java.io.*;
import java.util.Random;
import java.util.Scanner; 
public class WordGame
{
public static void main(String[] args) throws IOException
{
final int RANDOM_LETTERS_COUNT = 10;
final int TRIALS = 10;
int score = 0;

[Code] ....

View Replies View Related

How To Receive SMS Using USB Dongle

Oct 21, 2013

Code to receive a SMS using an USB dongle? or else how to write a code? I searched in the internet but couldn't find it.

I'm using Netbeans IDE.

View Replies View Related

Java Lotto - Randomly Generate Five-digit Number And Prompts User To Enter Five-digit Number

Sep 25, 2014

1. 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.here is my code. I have tried replacing the && statements with || and it always returns either case 1 or case default.

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]...

View Replies View Related

Send / Receive Mass SMS And Update Database

Aug 4, 2014

I have just taken it upon myself to attempt to develop an application using java that will implement several features for my aircraft maintenance unit. I've taken a few courses in Java and I am a computer science major, so I wanted to use this as a way to improve my coding skills while also improving the effectiveness of my unit.

Anyway my application needs to have these key features:

1. Access a recall roster that is in Excel format and read the names/phone numbers of up to 200 members. The application also needs to be able to update this information and save it.

2. The application also needs to be able to initiate a recall to some or all of the members on the recall roster via text message.

3. The application needs to be able to receive messages back and display them under each name from the recall roster.

My current plan is to set up a GUI that expands JButtons in a scrollable window as members are read in from the excel document. Upon clicking any of the buttons the person will be contacted individually via a custom message that can be typed in via a popup window after clicking it. Alternatively you can check a box next to any persons button to add them to the list of people to be contacted and then click a button that says "Contact those checked" or something along those lines. Finally there will be a button that just says initiate total recall and it will contact everyone.

As for the interface I want each button to be highlighted red until a response has been received from the person associated with that button, which will then be recorded under their contact information.

I've attached an extremely rough picture...

View Replies View Related

Swing/AWT/SWT :: How Can Two Different Objects Receive Notification Of Same Event

Feb 23, 2015

The scenario:

* A pop-up menu generates an array of rectangle objects; each rectangle having random x.y coords and colour.
* The number of rectangles in the array is user selected from the popup list.
* The APopUp class has a 'getter' method that returns the array.
* The pop-up object is instantiated in an object of the AFrame class.
* The AFrame object needs to get the array each time the popup changes its state.

The problem:
.
* As I see it, the AFrame object needs to informed of the pop-up's state of change event or does the problem lie in how I have decided
which responsibilities each class is to have? I've tried to be as logical as possible during planning.

In the days of FORTRAN or BASIC we would hammer a solution through with brute force, but I would like to keep to Java's philosophy
of encapsulation and clean interfaces and that it seems to has generated a impasse of brain warping proportions.

import java.awt.Frame;
import java.awt.Label;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
public class AFrame extends Frame implements ItemListener {

[code]....

View Replies View Related

How To Receive Some Data From Multiple Clients On Network

Apr 16, 2014

I got my first project in which i need to receive some data from multiple client on network regularly(say every second) and then process that data and stored it to the database and then GUI needs to be created which display data accordingly.

While thinking for the design i thought blocking queue to implement the same. Like producer receive data from the port into a string builder and put that into the LinkedBlockingQueue. Consumer will take this data , process some work on it and store it into the database.I am using sybase ase 15 as a database.

My question is as i am receiving data very frequently which require insertion , updation and search almost every second into the database. What is the best way to improve the performance.

say i have 2 types of data is coming one having keyword 'Alarm' and other having 'ceased' so i need to use something like this

common fields in both is name and number.

if (ceased)
search into the database for particular event for which this ceased receive using name and numbe rand update the another field into it Also make separate entry for it
else
make a entry

Also as i am using 2-3 thread for consumers and thread = Number of client for the producer. So i thought to use synchronization at the consumer side which writes data into the database such that only 1 thread can write it.

View Replies View Related

JOptionPane And StringBuilder - Display And Receive Information To / From The User

Mar 6, 2014

I'm using the JOptionPane to display and receive information to/from the user. In addition to this, I am using StringBuilder to receive inputs from the user and then manipulate (append) that input to display the desired output.

//Example

(JOptionPane): "Enter text"
(user input): Java is cool!
(program): *stringBuilder.append(" I love it!")
JOptionPane.showMessageDialog( );
.....

Psuedo-like code. The problem is that showMessageDialog(null, string) and not showMessageDialog(string, string). I want to display the enter text: " Java is cool! I love it! " in the JOptionPane. How do I accomplish this, since showMessageDialog only accepts (null, string).

View Replies View Related

Receive Data From Midi Device With Java Sound API

Mar 15, 2014

I haven't been able to find a cut and paste working example of how to receive MIDI data from a MIDI device, like my piano, and display something to System.out.There are all sorts of examples for synthesizers, sequencers and sending data to a MIDI device, but I have not been able to find a single example of how to receive MIDI data and just display a simple message.

I just need something simple that works to start playing with it, and understanding how it works. Having a working example would also support understanding the Sound API descriptions. They read like differential equations texts books to me, i.e. not clear at all.

I have a working example of how to poll all devices and getDevice.info, which is supposed to then be used to address a specific MIDI device.

I've also looked at a number of books, in the store and on line.I haven't seen a single example anywhere.the closest I found to working examples was on StackOverflow, but I didn't understand some of the other code in the examples, which may or may not have been working correctly anyway.

View Replies View Related

Receive Input Events From A MIDI Interface Device

Sep 9, 2014

Using JVM under OSX 10.9.4?:

Receive input events from a MIDI interface device.

This has suddenly stopped working for me after years of using the Java MIDI software.

I have tested this on two different macbook pro's.

I have a variety of MIDI interfaces from different manufacturers. I can find the devices using MidiSystem.getMidiDevice. But I cannot get them to see any input MIDI events.

I can create events in code and send them to output devices and have them seen by those devices. It's just the input that seems to be broken.

I have tried using previously working software I having been developing for years and I have tried with a very simple test program.

View Replies View Related

Servlets :: Send And Receive Object Between Client And Server

Jul 6, 2014

I write a Client/Server program,trying to send and receive a object between client and server. I use the ObjectStream but there exists an EOFException on the client side when invoking readObject() .... I've tried many times but couldn't figure it out ...

server-side code

protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
try{
ObjectOutputStream out = new ObjectOutputStream(resp.getOutputStream());
ObjectInputStream in = new ObjectInputStream(req.getInputStream());
PersonalData pe = (PersonalData)in.readObject();
System.out.println(pe.getYearlySalary());

[Code] .....

View Replies View Related

Netbeans - Application To Send And Receive Data Via RS 232 Standard

Mar 2, 2014

I'm using netbeans to develop an application to send and receive data via RS 232 standard. I can send data but I can't read it.what can I do? I have this message in the console: Underlying input stream returned zero bytes. (I must use also threads to have application in real time but I don't understand very well....

View Replies View Related

Receive Information (Number) From User And Calculates Its Total

Apr 19, 2014

I wanted to write a simple code that receives information from the user (double-digit number and above) and calculates it's numbers.

For instance- The user wrote a number- 234, the software will return the number 9 (2+3+4 = 9).

Tried to use a loop for that, but I got stuck since I didn't know what to write.

This is what I've wrote so far

Java Code:

import java.util.Scanner;
public class Calculate {
public static void main(String[] args) {
System.out.println("Please type a number larger than 9");
Scanner type = new Scanner(System.in);
String number1 = type.nextLine();

for( int i = 0; i < number1.length(); i++ ){
int calculate = number1.charAt(i);
}
}
} mh_sh_highlight_all('java');

View Replies View Related

Java Servlet :: How To Receive Parameters From A Form And Insert Values In DB

May 23, 2012

I'm trying to create a Servlet that takes input from a form and process it and insert it in database.tablename.

My MAIN ISSUE IS WITH THE NUMBER OF COLUMNS THAT WOULD BE DYNAMIC AND THUS CANT RECEIVE THE PARAMETERS IN STATIC CODE.

Here is the form code

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<form action="Test" method="post" />
<table width="90%" border="1" cellspacing="1" cellpadding="1">

[Code] ....

And here is the Servlet

import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.io.*;
public class Test extends HttpServlet {

[Code] ....

This is the basic code structure and I'm trying to figure out this special case with handling the multiple parameters:

I don't want to use String []a=request.getParameterValues("studentname"); as hard code. The reason being the number of rows will be diyamic and I would like to get the column name and then then use an array of string to take values. But how can I connect these to form a query so that the rows goes on inserted one after other.

View Replies View Related

A Single Java Program To Receive And Send Plain Text Through Different Ports?

Jan 30, 2014

I have programmed a Router class which has two methods, receive and send.In receive method it receives the plain text from the server through port 2000.Its now all cool.In send method it sends the message to a client through the port 2001 but at the client i get an exception

connection refused:connect
import java.io.*;
import java.util.*;
import java.net.*;
import java.sql.*;
class Router {
String str;
public void receive()

[code]....

View Replies View Related

Can't Seem To Get Value For Integer 1 And Integer 2 To Pass With SetValue Method

Aug 10, 2014

public class MyInteger {
private int value;
public MyInteger(int number){
value = number;
System.out.println("Constructor created with value of " + value);

[code]....

I can't seem to get the value for integer1 and integer2 to pass with the setValue method. I get a runtime error stating the I need to have an int value for these two integers.

View Replies View Related

Opoly Game - Goal Of The Game Is To Reach Or Exceed Reward Value 1000

Mar 12, 2015

Opoly works this way: The board is a circular track of variable length (the user determines the length when the game app runs). There is only one player, who begins the game at position 0.

Thus, if the board length is 20, then the board locations start at position 0 and end at position 19. The player starts with a reward of 100, and the goal of the game is to reach or exceed reward value 1000. When this reward value is reached or exceeded, the game is over. When the game ends, your program should report the number of turns the player has taken, and the final reward amount attained.

In Opoly the game piece advances via a spinner - a device that takes on one of the values 1, 2, 3, 4, 5 at random, with each of the five spin values equally likely.

Although the board is circular, you should draw the state of the board as a single "line", using an 'o' to represent the current player position, and * represent all other positions. Thus if the board size is 10, then this board drawing:

**o******

means that the player is at location 2 on the board.

Here are the other Opoly game rules:

If your board piece lands on a board cell that is evenly divisible by 7, your reward doubles.

If you land on the final board cell, you must go back 3 spaces. Thus if the board size is 20, the last position is position 19, and if you land there, you should go back to position 16. (If the position of the last cell is evenly divisible by 7, no extra points are added, but if the new piece location, 3 places back, IS evenly divisible by 7, then extra points ARE added).

If you make it all the way around the board, you get 100 points. Note that if you land exactly on location 0, you first receive 100 extra points (for making it all the around), and then your score is doubled, since 0 is evenly divisible by 7,

Every tenth move (that is, every tenth spin of the spinner, move numbers 10,20,30,... etc.), reduces the reward by 50 points. This penalty is applied up front, as soon as the 10th or 20th or 30th move is made, even if other actions at that instant also apply. Notice that with this rule it's possible for the reward amount to become negative.

Here is the driver class for the game:

import java.util.*;
public class OpolyDriver{
public static void main(String[] args){
System.out.println("Enter an int > 3 - the size of the board");
Scanner s = new Scanner(System.in);
int boardSize = s.nextInt();

[Code] ....

heres the methods:

REQUIRED CODE STRUCTURE: Your Opoly class must include the following methods (in addition to the Opoly constructor) and must implement the method calls as specified:

playGame - The top-level method that controls the game. No return value, no parameters. Must call drawBoard, displayReport, spinAndMove, isGameOver.

spinAndMove - spins the spinner and then advances the piece according to the rules of the game. No return value, no parameters. Must call spin and move.

spin - generates an integer value from 1 to 5 at random- all equally likely. Returns an integer, no parameters.

move - advances the piece according to the rules of the game. No return value, takes an integer parameter that is a value from 1 to 5.

isGameOver - checks if game termination condition has been met. Returns true if game is over, false otherwise. No parameters.

drawBoard - draws the board using *'s and an o to mark the current board position. Following each board display you should also report the current reward. No return value, no parameters.

displayReport - reports the end of the game, and gives the number of rounds of play, and the final reward. No return value, no parameters.

View Replies View Related







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