Insert While-loop To Prompt User For Yes Or No

Apr 15, 2015

public static void getInput(int [] student, int []test1,int []test2,int []test3,
int [] test4, int [] test5) {
int stuId = 0;
int t1 = 0;
int t2 = 0;
int t3 = 0;
int t4 = 0;
int t5 = 0;
int h = 0;
char answer = '@';

[Code] ....

View Replies


ADVERTISEMENT

Prompt For User Input At The End Of First Loop

Mar 3, 2014

I am having a problem with code that I've written, the problem occurs when I try to prompt for user input at the end of the first loop. What happens is the println fires but the prompt never does and it exits the loop.

Java Code:

import java.util.Scanner;
public class Lab3test
{
public static void main( String[] arguments )
{
//Variable declaration

[Code] ....

View Replies View Related

Code Up With A Loop That Prompt User To Say If Program Should Run Again

Sep 10, 2014

I am still relatively new to java and am working on a lab program. I have already met the requirements and am trying to spice my code up with a loop that prompts the user to say if the program should run again. This is what I have so far:

package lab2;
import java.util.Scanner;
public class OrderedPairTest{
public static void main(String[] args){
boolean retry = true;
while(retry == true){

[code]....

However, it is giving me an error after the user inputs "y" in for the answer to run again. What did I do wrong?

Error code is: Exception in thread "main" java.util.NoSuchElementException: No line found at java.util.Scanner.nextLine(Unknown Source) at lab2.OrderedPairTest.main(OrderedPairTest.java:11)

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

Random Number With User Prompt?

Sep 8, 2014

I am wanting this program to prompt the user to enter a maximum value and a minimum value and the program should in theory generate a random number for the output. Here is my logic:

int maxRange1;
int minRange1;
static int range;
static Random gen;

Then in my mail argument:

gen = new Random();
Scanner input = new Scanner(System.in);
System.out.print("Enter the maximum number: ");
int maxRange1 = input.nextInt();

[Code] ....

I am able to return both the user prompts and get the inputted answer to appear but I am not getting a response for the prompt "The random number is: ".

View Replies View Related

Prompt User To Enter A String

Feb 15, 2015

I am suppose to design a problem the prompts the user to enter a String. Based on the input from the user, have the program prompt with a full description of the playing card entered. Below is a table of the notation and meaning:

Notation Meaning
A Ace
2...10 Card Values
J Jack
Q Queen
K King
D Diamonds
H Hearts
S Spades
C Clubs

Use the .charAt(...) to extract each character from the user's input and build a switch statement to determine the full description.

import java.util.Scanner;
public class PlayingCardIdentifier {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a card notation: ");
String s = input.nextLine();

[code]...

View Replies View Related

DiceSum - Prompt User For A Desired Sum

Nov 16, 2014

Write a method named diceSum that prompts the user for a desired sum, then repeatedly rolls two six-sided dice until their sum is the desired sum. Here is the expected dialogue with the user:

Desired dice sum: 9
4 and 3 = 7
3 and 5 = 8
5 and 6 = 11
5 and 6 = 11
1 and 5 = 6
6 and 3 = 9

This is my code:

import java.util.Scanner;
import java.util.Random;
public class mod {
public static void main(String[] args) {
diceSum();

[Code] .....

it works for numbers 2 - 4, but any number from 5 - 12 just prints one output, which is not the correct desired sum.

View Replies View Related

Can Insert While Loop In Switch Statement?

Dec 8, 2014

I am trying to add a while loop into my switch statement. If you run the program, it will ask to enter the class grade (9,10,11, or 12). If you insert 5, it will say to try again. But, if you enter a wrong number twice, it will continue on to the next part of the program, which is asking how many students are in the class. Therefore, I believe a while loop would work, but it is not working at all. The program still runs, just doesn't fix the error. The program is below:

import java.util.Scanner;
public class stephProject {
public static void main(String[] args) {
//call method
welcomeMessage(); //method 1 of 3

[Code] ....

View Replies View Related

Prompt User To Enter Integer From 1 To 15 And Displays A Pyramid

Jun 1, 2014

The exercise sounds like this : Write a program that prompts the user to enter an integer from 1 to 15 and displays a pyramid , as shown in the following sample run (my code displays correctly the first 9 lines):

1
2 1 2
3 2 1 2 3
4 3 2 1 2 3 4
5 4 3 2 1 2 3 4 5
6 5 4 3 2 1 2 3 4 5 6
7 6 5 4 3 2 1 2 3 4 5 6 7

The problem is when i input a number greater then 9 as it requires 2 spaces . I m pritty sure i solved it incorrectly or at lost not optimal as i m using a string that decreases on each line to create the pyramid effect.

import java.util.*;
public class C5_17 {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.println("Enter the number of lines: ");

[Code] ....

View Replies View Related

Prompt A User To Enter Three Tasks And Their Priorities In A Driver

Oct 31, 2014

My full instructions are to Design a Java interface called Priority that includes two methods and two constants. The methods are setPriority and getPriority. The constants are MIN_PRIORITY with value 1 and MAX_PRIORITY with value 6. The interface should define a way to establish numeric priority among a set of objects. Design and implement a class called Task that represents a task (such as on a to-do list) that implements the Priority interface. Assume that Task has two attributes (instance data): name and priority. Define the Task constructor to accept and initialize the name of the task. Each newly created Task should have priority equal to MIN_PRIORITY (the constructor should initialize priority to MIN_PRIORITY). Priorities can be changed using setPriority method. Create a driver class TaskDriver that should do the following: prompt the user to enter three tasks and their priorities, and then print the tasks in the order of decreasing priorities. If the user enters an invalid priority that is less than MIN_PRIORITY or greater than MAX_PRIORITY, then the user should be asked to enter priority again until a valid priority value is entered.

So far I have:

public interface Priority
{
public void setPriority(int level);
public int getPriority();

[Code].....

View Replies View Related

Prompt User To Enter Value Of Their Savings For N Number Of Weeks

Oct 19, 2014

So I have this program where i have to prompt user to enter a the value of their savings for n number of weeks (quarters dimes nickels pennies) and the program outputs the total of savings an average of saving per week and an estimation of saving per year.

I managed to do the first step but the problem is that when they enter the value of their savings i don't know how to save the value of each(quarters dimes nickels and pennies) to make the calculations? Here is what i have so far

import java.util.Scanner;
 public class yearlySavings
{
 public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
int numberOfWeeks = 0; // initialize value of numberOfWeeks
 
[Code] .....

View Replies View Related

Decoder Ring - Prompt User For A Message To Decode

Nov 7, 2014

So it is the question: This program implements a simple "decoder ring". It will prompt the user for a message to decode and decode the message based on the following substitution rules:

ABCDEFGHIJKLMNOPQRSTUVWXYZ will map to
ZEBRASCDFGHIJKLMNOPQTUVWXY

abcdefghijklmnopqrstuvwxyz will also map to
ZEBRASCDFGHIJKLMNOPQTUVWXY

any other characters (like space, punctuation, will map to themselves)

so if it sees an 'A' (or an 'a'), it will map to 'Z', etc... All i could think of is this but can't figure out the rest.

import java.util.Scanner;
public class DecoderRing
{
public static void main(String[] args)
{
String1[] = 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z';
String2[] = 'Z','E','B','R','A','S','C','D','F','G','H','I','J','K','L','M','N','O','P','Q','T','U','V','W','X','Y';
}
}

Not sure, what things are necessary such as switch statements or if and else or for loops and such...

View Replies View Related

Search Matrix For The Element With Highest Value - Prompt User With Location

Feb 11, 2015

I have to create a program that asks a user to enter an amount for rows and an amount for columns. After they input both amounts, they must fill in the matrix with values (values of double data type). After they enter the values, the program is suppose to search the matrix for the element with the highest value. Once it is found, the user will be prompted with the location of the highest value within the array. I got it to work as to where the user inputs the values and he/she will receive a location of an element. However what they receive is incorrect.

For example

"Enter number of rows: 3
Enter number of columns: 4
Enter values: 23.5 6 13 2
1 5 6 3
7 5 9 2"

Once they enter the last value, they will be prompted with

"The highest element is located in 34".

As you can tell, the highest element is located in 01. I think when the user is prompted with the values that they enter for the rows and columns. How can I modify my code as to where it shows the actual location of the highest value?

View Replies View Related

Test Program That Prompt User To Enter N And Displays N-by-b Matrix

Nov 25, 2014

I did a problem from my book which is "Write a method that displays an n-by-n matrix. Each element is 0 or 1, which is generate randomly. Write a test program that prompts the user to enter n and displays the n-by-b matrix".

So if a user would enter 3, and output could be 0 1 1
0 1 0
1 0 1

So here's my question... I was able to get the program to work in the way my book describes (by just writing the code in the class with the main), but for practice, I want to learn how to do this OOP-style...

I'm not sure how to do this, though, since the method is a void method, so I can't seem to call it within a toString method.

import java.util.Scanner;
public class MatrixTest {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter an int");
int number = input.nextInt();
MatrixClass mc = new MatrixClass(number);

[Code] .....

View Replies View Related

Prompt User To Input Integer And Then Output Both Digits Of Number And Their Sum

Jun 7, 2015

Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits. 
 
Now I have a code for spacing out the integers, and I have a separate code for adding the digits. But I am not sure how to merge them together. Both of them work independently
 
Spacing code:
import java.util.*;
public class SumoftheIntegers
{
static Scanner console=new Scanner(System.in);
public static void main(String []args) {
int num1, test, rem;
int counter = 0;

[Code]...

Now the sum of the integers code:
 
import java.util.Scanner;
public class sum
{
    public static void main(String[] args)
    {
        // Create a Scanner
        Scanner input = new Scanner(System.in);
// Enter amount
        System.out.print("Enter an integer: ");
        int integer = input.nextInt();

[Code]...

View Replies View Related

Prompt User For Input Number And Check If It Is Greater Than Zero - Java Multiplication

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

Add Integers To ArrayList And Prompt User To Delete Specific Numbers Not Required

Jan 21, 2015

This program simply adds integers to an ArrayList and then prompt the user if they would like to delete specific numbers that they don't want.

The output that I get when I want to delete numbers like 2 and 4 from 1 2 3 4 5 is 1 2 3 4 5 instead of 1 3 5.

Java Code:

import java.util.ArrayList;
import java.util.Scanner;
public class AL
{
// A regular array like int arr[] has to have its size declare before run-time and it's not dynamic which mean it can not grow or expand on its own.
static Scanner input = new Scanner(System.in);
// You have to use reference types(Integer, Double, Float); not primitive types(int).

[Code] .....

View Replies View Related

Making Vending Machine - Asking User To Insert More Money

Sep 23, 2014

So I am making a vending machine and am having trouble knowing what exactly to use or how to go about giving the user a error message depending if they initially added enough money for their choice of drink. So if the user only input 1 dollar, and the drink they select is $1.25, they need to add the $.25, but how do I implement that in this code?

Here is my code along with the zip file just in case.

package vending.sample;
import java.util.Scanner;
public class VendingSample {
public static void main(String[] args) {
int coke = 1, sprite = 2, DrPepper = 3, Pepsi = 4, Fanta = 5, Water = 6, selection, i;
double change, total;

[Code] ....

View Replies View Related

Writing A While Loop To Read Positive Integers From User Until User Enters EOF Character

Feb 24, 2014

import java.util.Scanner;
public class Project_5
{
public static void main (String[] args)
{
Scanner input= new Scanner (System.in);

[code]....

So I'm attempting to have this program take the users input of integers, pressing enter in between each one. If they enter a negative number it lets them know that its invalid. At the end of the program it takes all of the valid integers entered and must add them and average them. I've put the final println in there as a placeholder. If the user types in "6" then presses enter and types in "3" , the output is:

There were 3 valid numbers entered.
The sum of the valid numbers was --- and the average was ---.
There were 0 invalid numbers entered.

It then continues on allowing the user to enter more values. Here is the example output for correct code"

Enter a positive value (EOF to quit): 4
Enter a positive value (EOF to quit): 7
Enter a positive value (EOF to quit): 8
Enter a positive value (EOF to quit): 2
Enter a positive value (EOF to quit): -1
The number "-1" is invalid.

Enter a positive value (EOF to quit): 8
Enter a positive value (EOF to quit): 0
Enter a positive value (EOF to quit): -4
The number "-4" is invalid.

Enter a positive value (EOF to quit): CTRL-D

There were 6 valid numbers entered.
The sum of the valid numbers was 29 and the average was 4.83.
There were 2 invalid numbers.

View Replies View Related

Servlets :: Capture Keystroke From User In Textarea And Insert Details Into Text File Using Java

May 6, 2014

i am trying to do a program captures keystroke and mouseclick from user in a textarea and insert the details intoa text file using java. Mainly such as delay between keys, no. of times backspace being pressed, alt tab press and copy paste mouse click.

View Replies View Related

How To Set A User Controlled Loop

Jan 21, 2015

Here is my problem to solve : Find the smallest value Write an application that finds the smallest of several integers. Assume that the first value read specifies the number of values to input from the user.

I do not even know where to begin other than creating a scanner for the user input. But how do I take that user inputed number to create the loop?

View Replies View Related

User Must Get Three Random Numbers In A Row - Do While Loop

Feb 12, 2015

I need to fix a program in which the user must get a three random numbers in a row. They have five chances. This is what i have so far:

public static void main(String[] args)throws IOException {
// TODO code application logic here
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int num1=(int)(Math.random()*(9-0));
int num2=(int)(Math.random()*(9-0));
int num3=(int)(Math.random()*(9-0));

[Code] ....

View Replies View Related

How To Continue With Loop If User Decides To Not Quit

Mar 29, 2015

I have this program I have to write(attached). I am having problems with what the structure will look like. The following what I have so far. The questions I have are in bold.

>get userInput of how many observations

>for(int i = 1; i <= userInput; i++)
>for(int j = 1; j <= 1; j++)
>use a switch(case) method to ask user to select an option(1,2,3)
>example, user chooses option 1:
>ask to input time
>print displacement
>ask user to stop application(Y/N)
>IF "No" is selected --------->>

How do I continue with the loop if user decides to not quit? -- And do I need to put this in each 'case'?

View Replies View Related

Using While Loop For Printing User Entered Name From Console

Jul 2, 2014

Ask user to enter a name alphabet by alphabet, and print d whole word as output,,,,,, use while loop?Since i am new to JAVA..i have no clue on how to begin?

View Replies View Related

Airplane Seat Reservations - Loop Until User Hits 0

Nov 11, 2014

I'm writing a classic airplane seating program. The program runs fine except for two things:

1) I want the user to exit the program when 0 is inputted (program also quits when all seats are reserved - this works fine already). Now the program quits when user hits blank line with enter. How to fix this and make 0 the exit key?

2) I would like for there to be a line below the seating chart saying that there are XX number of seats available. When user makes reservations, the line should update every time under the seating chart saying that there are such and such number of seats available. How to implement this?

import java.util.*;
public class OmaAirplane {
public static void main(String[] args) {
System.out.println("Welcome to the seat reservation system!");
char[][] seats = new char [8][6];
ArrayList<String> reservedSeats = new ArrayList<>();
for (int i=0;i<8;i++){

[code]....

View Replies View Related

Simple For Loop - Determine Factorial Of A Number Entered By User

Jun 28, 2014

I'm trying to learn Java and my current project is to write a short program to determine the factorial of a number entered by the user. I haven't looked. There may be a method that will do it, but I want to use a for loop specifically.

What I have compiles just fine. I'm actually pretty thrilled just with that. Here is what I have:

class factorial {
public static void main( String[] args) {
Scanner scan = new Scanner(System.in );
int num;
int product = 1;

[Code] ....

View Replies View Related







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