While Loop In Combination With A Scanner

May 17, 2014

I have the following task given to me (to be solved in NetBeans) :

View the contents of the file tuinman.txt: each line has a (real) number, followed by a line text.

Write the readGardener () method that reads the file completely. Only if the number is negative, write the rest of the line. (For each input line, a new line output.)

Extra: Adjust your method so you get the text after each negative number, written "word by word", among themselves. A word can contain characters that are not "letters" are (,,. '") - ,this you may ignore.

"tuinman.txt" is dutch for "gardener.txt". This txt file is located in the same map where build,nbproject,src, etc... are located. I couldn't solve this task so i looked at the solution. It didn't work... So i tried the solution of the extra bit:

package labo.pkg2;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Methods {
public void readGardener() throws FileNotFoundException {

[Code] ....

The txt file is added as an attachment to this post.

The weird thing is, the first thing the program prints is "Van" "morgen" "ijlt",... wich are words from line 19 in the txt file. All the ones before line 19 the program won't print, even if the number is negative. Even weirder, the next thing that is printed after line 19 is the NUMBER from line 20, nowhere in this code do i tell the program to print a number, and yet it does... But that's not all! From line 19 on, he just prints every single thing in the document except for the negative number, if your mind didn't explode already, it sure did now!

So in short: I need some code that prints all the lines from the txt files that start with a negative number. Only the text may be printed though, there may be no numbers in the output!

The txt file, i couldn't add it as a attachment

123
-456,12 De tuinman en de dood
184,67 was hij, Kees, de enige die het zag, want niemand lette d'r op...
-845,14
-8,12452 Een Perzisch Edelman:
157,24 Dus daar gaan we dan.

[Code] ....

View Replies


ADVERTISEMENT

Code Not Running Scanner NextLine After Using Scanner NextInt?

Feb 14, 2015

package jdbc;
import java.sql.*;
import javax.sql.*;
import java.util.*;
public class Jdbc {
public static void main(String[] args) {

[code]....

View Replies View Related

Setting Up A Test For Combination Method

Nov 18, 2014

I'm having trouble setting up a test for my combination method.Here's the method (It basically finds the most amount of characters that both substrings share and combines the two using the number of shared characters as a breaking point):

public static String combination(String str1, String str2, int overlap) {
assert str1 != null : "Violation of: str1 is not null";
assert str2 != null : "Violation of: str2 is not null";
assert 0 <= overlap
&& overlap <= str1.length()
&& overlap <= str2.length()
&& str1.regionMatches(str1.length() - overlap, str2, 0, overlap) : ""
+ "Violation of: OVERLAPS(str1, str2, overlap)";

[code]....

View Replies View Related

Passing Object As Parameter - Combination Values Are All Zero

Mar 8, 2015

I have an object that has an instance of another object class as its parameter :

CombinationLock oneHundred = new CombinationLock(28,17,39);
Locker Mickey = new Locker(100, "Mickey", 3, oneHundred);

This is for a locker, which has a combination assigned to the student. Within the locker class I have the following constructor:

public Locker(int locker, String student, int numberOfBooks, CombinationLock combo) {
this.locker = locker;
this.combo = combo;
this.student = student;
this.numberOfBooks = numberOfBooks;
}

combo is the private CombinationLocker object I created within the Locker class. Do I need to pass the combo object on to the CombinationLock class? For reason, I do not comprehend, the combination password from the main class is not passing through to the CombinationLock class, and the combination values are all zero.

View Replies View Related

Repaint Work In Combination With PaintComponent (Graphics)?

Oct 3, 2014

I am teaching myself AWT/Swing ... It concerns an application that creates dynamic graphics using the Graphics class. I understand that the code that creates graphics should be put in a "paintComponent" method of a (descendant of a) JPanel class. And that when you want to change something on this panel outside "paintComponent", you have to call the "repaint" method, that somehow causes "paintComponent" to be invoked.

However, I don't fully understand the explanation of the example at [URL]... . It concerns an application that moves a red square when a mouse button is clicked. The code can be found at the link, but I also repeat it below.

package painting;
import javax.swing.SwingUtilities;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseEvent;

[Code]...

This code indeed works. However, I don't understand why. The explanation at the Oracle site is the following.

Because we are manually setting the clip, our moveSquare method invokes the repaint method not once, but twice. The first invocation tells Swing to repaint the area of the component where the square previously was (the inherited behavior uses the UI Delegate to fill that area with the current background color.) The second invocation paints the area of the component where the square currently is.

However, what I don't understand: when repaint is first invoked, squareX and squareY still have their old values. If the invocation of repaint simply causes an invocation of paintComponent, then paintComponent should draw a red square at (squareX, squareY). Just like the second invocation of repaint causes paintComponent to draw a red suare at the new values of (squareX, squareY). Instead, the first invocation results in the red square being wiped out by the background color.

So apparently, the first invocation of repaint does not simply cause an invocation of paintComponent. What does it do?

View Replies View Related

Swing/AWT/SWT :: Creating A Combination Lock That Consist Of Three Strings

Oct 23, 2014

I need to use a counter to keep track of user's input. In this class I am trying to create a combination lock that takes three strings. In the tester class the user inserts three strings and both are compared to see if users input matches correct combination. I have no errors only problem is the setPosition method. My output is always false.

public class CombinationLock {
private String first;
private String second;
private String third;
private String firstGuess;
private String secondGuess;
private String thirdGuess;
private boolean open;
private int counter;

[code]....

View Replies View Related

Image Processing Pattern Matching / Combination Algorithm

Jun 9, 2014

The problem I am trying to solve relates to block-matching or image-within-image recognition. This is an algorithm problem I am working on in java, but computationally, my computer can't handle generating all the combinations at one time.

I see an image, extract the [x,y] of every black pixel and create a set for that image, such as

{[8,0], [9,0], [11,0]}

The set is then augmented so that the first pixel in the set is at [0,0], but the relationship of the pixels is preserved. For example, I see {[8,0], [9,0]} and change the set to {[0,0], [1,0]}. The point of the extraction is that now if I see {[4,0], [5,0]}, I can recognize that basic relationship as two vertically adjacent pixels, my {[0,0], [1,0]}, since it is the same image but only in a different location.

I have a list of these pixel sets, called "seen images". Each 'seen image' has a unique identifier, that allows it to be used as a nested component of other sets. For example:

{[0,0], [1,0]} has the identifier 'Z'

So if I see:

{[0,0], [1, 0], [5,6]}

I can identify and store it as:

{[z], [5, 6]}

The problem with this is that I have to generate every combination of [x,y]'s within the pixel set to check for a pattern match, and to build the best representation. Using the previous example, I have to check:

{[0,0], [1,0]},
{[0,0], [5,6]},
{[1,0], [5,6]} which is {[0,0], [4,5]}
{[0,0], [1,0], [5,6]}

And then if a match occurs, that subset gets replaced with it's ID, merged with the remainder of the original set, and the new combination needs to be checked if it is a 'seen image':

{[z],[5, 6]}

The point of all that is to match as many of the [x,y]'s possible, using the fewest pre-existing pieces as components, to represent a newly seen image concisely. The greedy solution to get the component that matches the largest subset is not the right one. Complexity arises in generating all of the combinations that I need to check, and then the combinations that spawn from finding a match, meaning that if some match and swap produces {[z], [1,0], [2,0]}, then I need to check (and if matched, repeat the process):

{[z], [1,0]}
{[z], [2,0]}
{[1,0], [2,0]} which is {[0,0], [1,0]}
{[z], [1,0], [2,0]}

Currently I generate the pixel combinations this way (here I use numbers to represent pixels 1 == [x,y]) Ex. (1, 2, 3, 4): Make 3 lists:

1.) 2.) 3.)
12 23 34
13 24
14

Then for each number, for each list starting at that number index + 1, concatenate the number and each item and store on the appropriate list, ex. (1+23) = 123, (1+24) = 124

1.) 2.) 3.)
12 23 34
13 24
14
---- ---- ----
123 234
124
134

So those are all the combinations I need to check if they are in my 'seen images'. This is a bad way to do this whole process. I have considered different variations / optimizations, including once the second half of a list has been generated (below the ----), check every item on the list for matches, and then destroy the list to save space, and then continue generating combinations. Another option would be to generate a single combination, and then check it for a match, and somehow index the combinations so you know which one to generate next.

How to optimize what I am doing for a set of ~million items. I also have not yet come up with a non-recursive or efficient way to handle that each match generates additional combinations to check.

View Replies View Related

How To Generate Alternate Color Of Balls Combination For 3 Boxes

Feb 24, 2014

I am working on a project in which I have three box (as of now) and each box will have some color of balls. So I am storing them in a Map of String and List of String as mention below.

Map<String, List<String>> boxBallMap = new LinkedHashMap<String, List<String>>();

Data in the above map is like this -

Java Code:

{box1=[blue, red, orange]}
{box2=[blue, red]}
{box3=[blue, red, orange]} mh_sh_highlight_all('java'); ProblemStatement:-

Basis on the above input, I need to return a mapping which will be List<Map<String, String>>, let's say for above input, below mapping would be return as an output -

Java Code:

[{box1=blue, box2=red, box3=orange},
{box1=red, box3=blue},
{box1=orange, box2=blue, box3=red}] mh_sh_highlight_all('java');

Here if you see, each row has alternate color of balls for each box - meaning blue for box1, red for box2, orange for box3 in first row. I cannot have same color of balls in each row. So this combination is not possible as it has same color of balls for two boxes in one row.

Java Code: {box1=blue, box2=blue, box3=orange} mh_sh_highlight_all('java');

And also, in the second row, I won't use those balls which have been used in the first row for that box. In second row, box1 has red why? bcoz blue was already used in the first row for box1 and box3 has blue and no box2 in second row.

The output combination is getting generated basis on the input being passed as shown above.

I started with the below code -

Java Code:

List<String> balls1 = Arrays.asList("red", "blue", "orange");
List<String> balls2 = Arrays.asList("red", "blue");
List<String> balls3 = Arrays.asList("red", "blue", "orange");
Map<String, List<String>> maps = new LinkedHashMap<String, List<String>>();

[Code] ....

Below is my method in which the crux of logic should be there

Java Code:

private static List<Map<String, String>> generateMappings(Map<String, List<String>> map) {
return null;
} mh_sh_highlight_all('java');

Below algorithm might work but still not sure how should I fit this in the code -

- sort the boxes by the number of balls they have in it (ascending, from the smallest to the largest box).
- while there are colors left
- loop over the sorted list of boxes
- in each iteration pick a color from the box (if there is one left), that is not already picked in the current iteration (of the while loop)

View Replies View Related

Validate String Whether It Is Combination Of Lowercase And Uppercase And Has Character

Jun 22, 2014

I have to validate a string whether it is a combination lowercase and uppercase and has the character '_'.

I m having trouble in framing the expression for these conditions in the matches function.

How it can be done..?? How to frame a the correct expression.

View Replies View Related

Telephone Number - Write To A File Every Possible Seven-letter Word Combination

Nov 23, 2014

I am having some trouble with this program. The assignment is to write a program, given a seven-digit phone number, uses a PrintStream object to write to a file every possible seven-letter word combination that corresponds to that number. I have to avoid using 0 or 1. Here is my code.

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Scanner;
public class TelephoneGenerator
{
String phoneNumber;
char numberLetters[][] = {

[Code] ....

I am getting an error dealing with the main class.

View Replies View Related

Create N Number Of Flows With Any Combination Of Values - Search Match

Apr 12, 2015

I have a requirement like to attach most suitable flow  to a request
  
Flows should be like below (eg:Flow1) .We can create n number of flows with any combination of values.

When I tried to create a request that have all the  features in the flow. And I have to attach the most suited flow to that request.

Suppose my request have the feature  Place = Place1 and company =Comp1 and Job=Job1 .here most suitable flow is Flow1.

So my question is how can I implement the logic in java for getting the most suitable match.

View Replies View Related

Retrieving Result By User Input Different Combination Using String Tokenizer (MYSQL)

Mar 30, 2014

I am creating a simple Symptom Checker application. The problem I have is that I'm trying to retrieve user input (JTextField) by comma's using StringTokenizer which contacts the database for a result which matches the user's input (SELECT * FROM DIAGNOSIS WHERE ?, ?, ?) . It successfully finds the correct result however only in a particular format. Not different combinations....

for example, if I enter say within the JTextField: "tearful, nausea, lack of motivation" it will find the result successfully (as that is how it is formatted within the particular column (in the database table) i wish to display a result from) however, if i enter a different combination of these symptoms: "nausea, lack of motivation, tearful" - it will not find any result. I'm very unsure how to make it work regardless of what is inputted first, second or last.

Here is the code:

public void actionPerformed(ActionEvent e) {
try {
String abc = fieldsymp1.getText();
StringTokenizer str = new StringTokenizer(abc);
while (str.hasMoreTokens()) {
str.nextToken((", ")).trim();
 
[Code] ....

View Replies View Related

Vending Machine - Tell User Combination Of Coins That Equals To Amount Of Change

Jan 25, 2012

I have a simple java program to write which tells the user combination of coins that equals to the amount of change i.e:

user input 87

output:

3 quarters
1 dime
0 nickels
2 pennies

How the program remembers the remainder which is passed to the next column of let say dime

i.e

originalAmount = amount;
quarters = amount /25;
amount = amount % 25; <---- this is confusing for me?!?! how can the integer = integer % 25
dimes = amount / 10; <--- HOW THE PROGRAM remembers the "remainder" instead of the original user input as the code it self tells you dimes = amount where "amount" is what user input NOT remainder.

amount = amount % 10;
so on ....;

What I don't understand is HOW this algorithm works. I mean we have int amount where user inputs the number we get the first calculation amount/25 = how many quarters and then amount %25 WILL tell us about the reminder. By looking at this piece of code I would say that the system should start the calculation for the dimes again from the original number since the code says dimes = amount/10 AND amount = amount%10. My understanding is that the calculation should be done from the original user input.

Book or code it self is not clear for me how the reminder is "REMEMBERED" and then pass on to the next calculation>!?!?

UNLESS the code: amount=amount%25 gets the remainder so the next code under it is REQUIRED to read from the last prompt code.

View Replies View Related

Region Is Created Dynamically Using Combination Of Pre-existing Region

May 8, 2014

I'm trying to add a feature to my game where a region is created dynamically using a combination of a pre-existing region.This part of the game will be a sort of adventure where the place is different every time.This is a picture of the original location, when called, the server would copy parts of this region and make an instance of a new region.This new region will always have the coordinates [6, 6] as the starting room. Each room has a certain number of doors used to get across each room.Here's a picture of the new region and all the potential spots the rooms can be placed.

new DungeonFloor(new int[] { 8, 632 }, FloorType.BASE_FLOOR, new int[] { NORTH, SOUTH, EAST, WEST }),
new DungeonFloor(new int[] { 8, 630 }, FloorType.BASE_FLOOR, new int[] { NORTH, SOUTH, WEST }),
new DungeonFloor(new int[] { 8, 628 }, FloorType.BASE_FLOOR, new int[] { NORTH, SOUTH, }),
new DungeonFloor(new int[] { 8, 626 }, FloorType.BASE_FLOOR, new int[] { SOUTH, WEST }),
new DungeonFloor(new int[] { 8, 624 }, FloorType.BASE_FLOOR, new int[] { SOUTH }),

Here's a picture of the dungeons.The parameters are as follows

[] { regionX and regionY } // Used to copy the original location
Type of floor
The door directions of that original location

These are all the same room except the doors are different. Each room can be rotated to make the doors work.The problem:I need an algorithm that finds a starter floor with the correct number of doors, places it at (6, 6).Places the best boss floor at any region makes a map around the boss floor covering x number of rooms. x being a parameter that's sent with the method call.

The code so far:

List<DungeonFloor> allFloors = Arrays.asList(DungeonRepository.DUNGEON_FLOORS);
List<DungeonFloor> starterRooms = new LinkedList<DungeonFloor>();

for (DungeonFloor floor : allFloors) {
if (floors.type() == FloorType.BASE_FLOOR)
starterFloors.add(floor);
}

View Replies View Related

Unable To Print A Loop Inside Array Of Greater Size Than Loop Itself

Jan 27, 2015

I am trying to print a loop inside an array of a greater size than the loop itself. Like for example I have an array of size 7 but it has only 3 elements.

int[] array=new int[7]
array[0]=2;
array[1]=3;
array[2]=4;

now what I want to do is print these three numbers in a loop so that my array[3]=2;array[4]=3;array[5]=4 ...... till the last one. Also the array could be any size and not just 7.

View Replies View Related

While Loop Inside A For Loop To Determine Proper Length Of Variable

Feb 25, 2014

Here's the code: it's while loop inside a for loop to determine the proper length of a variable:

for (int i = 0; i < num; i++) {
horse[i]=new thoroughbred();
boolean propernamelength = false;
while (propernamelength==false){
String name = entry.getUserInput("Enter the name of horse "

[code]....

I was just wondering what was going on here -- I've initialized the variable, so why do I get this message? (actually the carat was under the variable name inside the parentheses.

View Replies View Related

When Type Quit To Close Outer Loop / It Still Runs Inner Loop

Nov 2, 2014

I have everything else working. My problem is that when i type "quit" to close the outer loop. It still runs the inner loop. The National Bank manager wants you to code a program that reads each clients charges to their Credit Card account and outputs the average charge per client and the overall average for the total number of clients in the Bank.

Hint: The OUTER LOOP in your program should allow the user the name of the client and end the program when the name entered is QUIT.In addition to the outer loop, you need AN INNER LOOP that will allow the user to input the clients charge to his/her account by entering one charge at a time and end inputting the charges whenever she/he enters -1 for a value. This INNER LOOP will performed the Add for all the charges entered for a client and count the number of charges entered.

After INNER LOOP ends, the program calculates an average for this student. The average is calculated by dividing the Total into the number of charges entered. The program prints the average charge for that client, adds the Total to a GrandTotal, assigns zero to the Total and counter variables before it loops back to get the grade for another client.Use DecimalFormat or NumberFormat to format the numeric output to dollar amounts.

The output of the program should something like this:

John Smith average $850.00
Maria Gonzalez average $90.67
Terry Lucas average $959.00
Mickey Mouse course average $6,050.89
National Bank client average $1,987.67

Code:

public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String name = "";
int charge = 0;
int count = -1;
int total = 1;
int grandtotal = 0;
int average = 0;
 
[code]....

View Replies View Related

Scanner Is Not Working

Apr 24, 2014

I wrote a piece of code:

for(int i = 0; i < x; i++){
System.out.println("Enter students full name:");
sName[i] = result.fullName(sc.nextLine());
sExam[i] = result.examName("VB");
System.out.println("Enter students exam score:");
int scor = sc.nextInt();
sScore[i] = result.examScore(scor);
sGrade[i] = result.examGrade(scor);
}

When i run it i get:

Enter number of students:
1
Enter students full name:
Enter students exam score:

The problem is, i cant enter "full name", program is just jumping to the next step "exam score".

View Replies View Related

Scanner Ignores Last Int

Feb 9, 2015

why does sevenPointsOrLess only work if I declare it as a String and use next() instead of nextInt()? Also why does it take part of the next line with it?

Here is the text I am trying to scan:

England,3,0,1,2,0
Samoa,1,0,3,0,1

Code:

lineScanner.useDelimiter(",");
country = lineScanner.next();
Won = lineScanner.nextInt();
Drawn = lineScanner.nextInt();
Lost = lineScanner.nextInt();
fourOrMoreTries = lineScanner.nextInt();
sevenPointsOrLess = lineScanner.next();

Results:

country = "England"
Won = "3"
Drawn = "0"
Lost = "2"
fourOrMoreTries = "2"
sevenPointsOrLess = "0 Samoa"

View Replies View Related

Scanner In Java

Jan 3, 2015

I'm trying to write a basic java program so that when I run it, I can store the names and codes of some of my school textbooks...I try the scanner statement to input the name of the book but an exception is thrown when I type the name of the book..I have attached the code for my program.

import java.util.Scanner;
public class Books{
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
System.out.print("Enter amount of products : ");
int products= s.nextInt();
long [] code= new long[products];
String[] names = new String[products];
for (int x=1;x<(products+1);x++){
System.out.println("Enter IMEI number "+x);
code[x] = s.nextLong();
System.out.println("Enter name "+x);

[code]....

View Replies View Related

Scanner Isn't Accepting Doubles

Jan 25, 2014

I had to use scanner to receive input from the user for a formula and everything compiled and worked correctly except when I entered a double into the Scanner, it only accepts ints and gives me this error every time I enter a double:

java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextDouble(Unknown Source)
at TestA1Q2.main(TestA1Q2.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:272)

I know that you usually get that error when the Scanner expects something else that is different from what you type and I have looked over my code time and time again and cannot find anything. I created a test program to see if it was just that problem and not something else in the code and I still got the same error but when I tried compiling and running it here browxy.com everything worked and I got the right answer for the formula. Here's the test I used:

import java.util.Scanner;
public class TestA1Q2 {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter a double");
double velocity = keyboard.nextDouble();
}
}

At this point I'm thinking it might be a problem with my install of DrJava and I've tried re-installing but nothing changed.

View Replies View Related

Scanner Cannot Be Used As Variable In If Statements?

May 18, 2014

I created a variable for the scanner called serena. Serena variable is equal to what the user inputs. My if statement says that if the answer the user enters is not equal to the actual answer then it is to display "wrong". It is a basic math game I am working on. NetBeans is telling me that I cannot use the scanner in an if statement?

package pkgnew;
import java.util.Scanner;
public class New{
public static void main(String args[]){
Scanner serena = new Scanner(System.in);
double fnum, snum, answer;

[Code] ....

Do I have to define Serena as whatever number the user inputs? If so, how?

View Replies View Related

Can Use Java Scanner With String?

Jan 18, 2010

I couldn't get this code working:

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

[Code] .....

Did i write something wrong or can't Scanner be used with String?

View Replies View Related

Scanner Array Initializing

Oct 12, 2014

Scanner sc = new Scanner(System.in);
Question question = new Question();
Quiz quiz = new Quiz();
System.out.print("Enter the prompt: ");
question.prompt = sc.nextLine();

[Code] .....

Here is the example run that I am trying to achieve:

* 1. Enter the prompt: What is the capital of the USA?
* 2. Enter a possible answer: New York City, NY
* 2. Is New York City, NY the correct answer (y/n)? n
* 3. Enter a possible answer: Pittsburgh, PA
* 3. Is Pittsburgh, PA the correct answer (y/n)? n
* 4. Enter a possible answer: Washington, DC
* 4. Is Washington, DC the correct answer (y/n)? y
* 5. Enter a possible answer: Chicago, IL
* 5. Is Chicago, IL the correct answer (y/n)? n

The problem is that my for loop runs through correctly the first time, but doesn't seem to react to me initializing my choices array after that. It ends up looking like this:

Enter the prompt: What is the capitol of the USA?
Enter a possible answer: New York City, NY
Is New York City, NY the correct answer (y/n)?n
Enter a possible answer: Is the correct answer (y/n)?

But I cannot understand why it's doing that.

View Replies View Related

Scanner Taking Input Twice

Oct 29, 2014

I have a small bug in my program. The user is asked what person(s) information they want to access but lets say they want captain they must enter "captain" twice. I think it will make more sense to you with the code. I have searched all over to see what is causing the bug but still have found no resolution. I even tried making two different scanners but that didn't work either.

I know the while loop (line 16) I am using is causing the bug because it works fine without that but then I cannot validate the input.

package myproject;
import java.util.Scanner;
public class Enterprise {
public static void main (String[]args){
String userInput;

[Code]......

View Replies View Related

Scanner NextLine Won't Enter Anything

Jan 26, 2014

My program is supposed to let me enter the following info for 3 employees: name, number of hours worked this week, and hourly pay rate. It lets me enter the name for the first employee, but for the second and third, it skips over the name and forces me to enter the number of hours worked and pay rate without a name. I have the code and the output posted below. First the program code:

Java Code:

import java.util.Scanner;
public class SalaryCalc {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String name;
double hours;
double rate;
double grossPay = 0;
double overtime;

[code]...

Enter hours worked this week: mh_sh_highlight_all('java'); Notice I can only enter the name for the first employee (Bigfoot). If I wanted to enter "Nessie" for my second employee's name, it skips over the name prompt and prompts me for the hours worked instead.

View Replies View Related







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