While Getting Input From User Check A Second Condition
Apr 22, 2015
Is it possible to wait for an input for a user and check in the meantime if something else is true?
Now if the server in the meantime says: there is no input needed and tells it the client.
Could the client now somehow change from
input.readLine() to another Method say: quit() ?
I am stuck there because I know the server sends: quit to the client1 but the client2 cannot react because it still waits for an input for the user.
Maybe something with Thread.sleep ?
View Replies
ADVERTISEMENT
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
Aug 26, 2014
The code for my button is below - I know it is wrong and that I need to change line 8 at least,so I am technically asking the property object if there is a key_name there but I dont quite get how to do that
//code for button
JButton btnSearch = new JButton("Search");
btnSearch.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//find selected command
String key_name = textFieldSearch.getText();
[Code] ....
I basically just want the user typed in word to be checked against a keyword in a proeprties file and if it exists, pull the key and the value back into a panel ....
View Replies
View Related
Mar 26, 2014
I need to display button based on the condition in xhtml page.
using JSF2 & richface 4.0
<c:forEach items="#{empList}" var="emp">
How to check condition like empList.size > 0 in xhtml?
if list is having value, need to show buttons.
View Replies
View Related
Apr 13, 2014
Write a program that prompts the user for an input number and checks to see if that input number is greater than zero. If the input number is greater than 0, the program does a multiplication of all the numbers up to the input number starting with the input number. For example if the user inputs the number 9, then the program displays the following sum:
9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1 = 362880
That's the question I'm getting and so far all I've got is
import java.util.Scanner;
public class Lab4Q3
{
public static void main (String[] args)
{
int keyboard;
[Code] .....
View Replies
View Related
Apr 15, 2015
I decided to code this quiz I took in class about asking the user to input a string and the code is suppose to check for upper case letters. If a upper case letter is found, it should increase a count by one. Once the check is done, it should display the number of uppercase letters. For some reason I am getting this weird compile error stating that symbols can't be found...
Java Code:
import java.util.*;
import java.lang.*;
public class StringCheck{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.println("please enter a string: " );
String s = input.nextLine();
[Code] ......
View Replies
View Related
Mar 18, 2015
I am trying to create a program that first asks the user for an input in the form: condition = value, where condition is a word from the set {limit, deficient, abundant, perfect, prime}, and value is a positive integer. Then it verifies the input. If the input is invalid it prints a message indicating that and terminates. If the input is valid it prints a table with the number of abundant, deficient, perfect and prime numbers less than or equal to N, where N = 1, 2, 3, ..., limit.
My problem is with the input validation. i want it to read the value as a string and verify if it's integer.
Here is my code
import java.util.Scanner;
public class Factors
{
public static void main (String[] args)
{
Scanner scan = new Scanner(System.in);
int n, f, fsum, p=0, a=0, d=0,pe=0,limit=0,abundant=0, deficient=0;
System.out.print("Enter stoping condition (condition = value): ");
String cond = scan.next();
[Code] ....
View Replies
View Related
Jan 24, 2014
I am using form based, declarative security approach. And, when some user, on login form enters user credentials (username and password), he is being redirected to certain/secured jsp page.
Part of that page content is:Hello <%=request.getUserPrincipal().getName().toString()%> You are able to view this page because you are authorized user.You can see that this is implemented using JSP scriptlet. And this works. I would like to use JSTL instead of scriptlet.
So, instead of scriptlet, I put this JSTL code: <c:out value="${requestScope.userPrincipal.name}"/>, but not getting user's username with it. Basically, I don't clearly understand where and how are these objects/user credentials being stored with Form based JAAS.
I would like on JSP page to check if some user is already logged in. So, if there is logged user to display user's name (also with JSTL).Something like this:
<c:if test="${not empty sessionScope.userPrincipal}">
User <c:out value="${sessionScope.userPrincipal.name}" />
</c:if>
Here I tried with sessionScope but still not getting anything.
View Replies
View Related
Dec 16, 2014
My program here asks for an unit to choose from (fl.oz, gal, oz, lb, in, ft, or mi), asks how much of it they have, and asks for the unit they wish to convert to (mL, l, g, kg, mm, cm, m, or km).
My program works, refusing to convert from silly conversions such as gal to cm, telling you to re-input if they enter anything other than fl.oz, gal, etc.
The only thing I cannot figure out is if the user inputs something like "foo" when the program prompts the user for how much of the unit they have. My goal is to have the program say something like "That is not a number! Please enter a numerical value."
My current dilemma right now is that if the user inputs something other than a number, it will catch the exception and print a line telling the user it's not a number, except, it does it infinitely (stuck in a loop). Here is my code:
import java.util.InputMismatchException;
import java.util.Scanner;
public class UnitConversions {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
double result = 0;
[Code] ....
View Replies
View Related
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
Mar 18, 2014
I have a question about how to check for a session as the user goes through different pages. I am using Java beans and EL to pass data from page to page but I cannot figure out how to check for a session on the pages without the use of a scriptlet with an if else statement in it.
I do not want the user to be able to access any pages unless they are logged in. With a scriptlet, I can create a statement that says if session exists show name else redirect to login page.
From what I have read and what some of the wonderful members here have told me, scriptlets are a big no no these days. So, how do I do these without the use of a scriptlet?
View Replies
View Related
May 1, 2014
I am trying to write a simple program that checks if a user's input has a specific letter using the ".contains" method but its not doing what i wanted to do. here is my code below.
import java.util.Scanner;
public class secret
{
public static void main(String args[]) {
Scanner sc;
char hidden='a';
String guess;
[Code] ....
View Replies
View Related
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
Apr 9, 2014
Write a java program that will ask a user to input grades until the user inputs the sentinel value -1. The program should test each input to determine whether 0<=grade<=100. If the grade entered is within this range, the program should print "Grade accepted;" if not, the program should print "Invalid input".
View Replies
View Related
Nov 4, 2014
I have been struggling with this program for weeks. This program is supposed to take a user's inputted odd number and then print out all prime numbers lower than that number.
public class PrimeNumber
{
Scanner scan = new Scanner(System.in);
int userNum;
String neg;
public void getUserNum()
[code]...
View Replies
View Related
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
Apr 9, 2015
Where do I input this segment?
Scanner user_input = new Scanner( System.in );// This line goes at the top with the other global variables
public void getUserInput(){
System.out.print("Enter litres: ");
litres = user_input.nextDouble( );
System.out.print("Enter mileage: ");
mileage = user_input.nextDouble( );
System.out.print("Enter speed: ");
speed = user_input.nextDouble( );
[Code] ....
This is my client file.
class Client{
public static void main(String []args){
Bike R1=new Bike(5.0, 60.0,30.0);//create bike object with params
Bike R2=new Bike();//without params
System.out.println(R1.increaseSpeed());//calling methods
System.out.println(R1.maxDistance());
System.out.println(R2.increaseSpeed());
System.out.println(R2.maxDistance());
}
}
View Replies
View Related
Nov 13, 2014
I have been coding in my class at school (Grade 11 Computer science) and i just downloaded the program on my computer at home, unfortunately i cannot access my computer notes at home and i also dont remember certian specifics of coding, so my question is how would i get user input to create a program. The comments are the parts i dont remember. (I am trying to slowly build my memory with this stuff)
Here is my code so far:
import java.util;
[highlight=java]
public class hello_world {
public static void main(String[] args) {
string name;
//WHAT DO I PUT HERE????
[code]....
View Replies
View Related
Apr 19, 2014
I'm working on creating a dice game and getting the users input is giving me a really hard time. I have the main game working but this part I'm stuck on. The problem is that it's not giving me the chance to enter the second input when I ask for the game.
//Create Scanner object
Scanner keys = new Scanner(System.in);
//Get chips
[Code]....
*****This is what I get when I run it
run:
How much money would you like to change? 50
You now have $50 in chips.
What game do you want to play? You did not pick dice.
View Replies
View Related
Oct 11, 2014
Is there a way you can control user input?
For example, is it possible to only allow the user to enter digits?
View Replies
View Related
Feb 4, 2014
I have been given a piece of work to do for College that requires me to format user input. For example: This is an example of text that will have straight left and right margins after formatting
will transform into:
This..is..an.example
of..text..that..will
have..straight..left
and...right..margins
after.....formatting
The user inputs the width, in the case above being 20. Each line has to therefore be 20 characters long. All spaces are to be replaced with full stops.
This.is.an.example.o
f.text.that.will.hav
e.straight.left.and.
right.margins.after.
formatting..........
public class Main {
public static void main ( String args[])
[code]....
View Replies
View Related
Jul 2, 2014
Goal is to get user input and sum together. I've tried it different ways. This is the one with the least amount of problems.
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: java.lang.Integer.parseInt
ArrayList<Integer> leftCU = new ArrayList<>(); {
System.out.println
("Please enter one at a time the number of CU's for each class that is left to complete. Enter Q when done.");
leftCU.add(in.nextInt());
[Code] .....
View Replies
View Related
Jan 9, 2015
I am trying to get user input for a char value and am having some difficulty getting input for a char value.
Java Code:
//imports packages
import java.io.*;
import java.text.DecimalFormat;
class ModuleCulminatingTask {
public static void main (String args []) {
//declares variables
float var3, var4;
long var5 = (int)(Math.random()*10);
[code]....
View Replies
View Related
Apr 10, 2014
I'm not sure what is wrong with my code:
import java.util.Scanner;
public class Main {
int age = 0;
System.out.println("Enter your age: ");
// Read in values
age = in.nextInt();
}
The in is underlined, telling me "cannot find symbol"
View Replies
View Related
Apr 19, 2014
I'm working on creating a dice game and getting the users input is giving me a really hard time. I have the main game working but this part I'm stuck on. The problem is that it's not giving me the chance to enter the second input when I ask for the game.
//Create Scanner object
Scanner keys = new Scanner(System.in);
//Get chips
System.out.print("How much money would you like to change? ");
int chips = keys.nextInt();
System.out.println("You now have $" + chips + " in chips.");
[code]...
This is what I get when I run it run/How much money would you like to change?
View Replies
View Related
Mar 25, 2014
Java Code:
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
public class SortTable {
public static void main(String args[]) {
Runnable runner = new Runnable() {
public void run() {
[Code]...
View Replies
View Related