Results 1 to 3 of 3
- 07-21-2007, 09:13 AM #1
Member
- Join Date
- Jul 2007
- Posts
- 1
- Rep Power
- 0
Extreme nooby having hard time with this app
Hello,
I have been reading this forums for a while trying to figure out a problem I am having with loops. I had to write this program for a java course I am taking, and I cant figure out how to make the program loop until "stop" is entered for the dname variable. I know this code is clunky, and there is a lot commented out from failed attemps at making it work, but I was wondering if someone could help me out a little here because I am at a complete loss (hence the late posting time lol). Thanks in advance!
-----Program pasted bellow this line -----
//
//
import java.util.Scanner;
import java.io.*;
public class Payroll
{
public static void main( String args[] )
{
Scanner input = new Scanner( System.in );
int hrate; //hourly rate
int hpw; // hours worked per week
int weekp; // Total weekly pay
// Name Variable delcared in-statement bellow (dname)
do
{
System.out.println("WELCOME TO THE PAY ROLL CALCULATOR");
System.out.print( "What is the Employees name?: " );
String dname = input.nextLine();
System.out.print( "What is the hourly rate?: " );
hrate = input.nextInt();
//if (hrate < 0) System.out.println("Wrong , postives only");
// hrate = input.nextInt();
// MUST ENTER A POSITIVE NUMBER FOR THIS VARIABLE, OR LOOP BACK AND PROMPT AGAIN
System.out.print( "How many hours worked in a week?: " );
hpw = input.nextInt();
weekp = hrate * hpw; // perform math operations
System.out.printf( dname ); //Name
System.out.printf( "'s Weekly Pay is $%d\n", weekp );
}
while( dname = stop );
// do {
// BufferedReader keybd =
// new BufferedReader(new InputStreamReader(System.in));
// } while (!dname.equals("stop"));
} // end method main
} // end class Payroll
- 12-05-2007, 10:00 AM #2
Member
- Join Date
- Dec 2007
- Posts
- 5
- Rep Power
- 0
RE: Extreme ...
Hi...the way i would do it is by doing the following:
Scanner in = ...
String dname = "";
dname = in.nextLine();
while(dname != "stop")
{
//do process here
//at the end u have to ask for another input
dname = in.nextLine();
}
//some other processes here...
- 12-05-2007, 07:24 PM #3
Similar Threads
-
Hello, first time here.
By ludragon in forum IntroductionsReplies: 2Last Post: 01-03-2008, 05:03 AM -
help with dates and time
By osval in forum New To JavaReplies: 3Last Post: 12-12-2007, 12:41 PM -
Time method
By carderne in forum New To JavaReplies: 5Last Post: 11-05-2007, 09:34 AM -
DataObject with the time given by me
By garinapavan in forum New To JavaReplies: 2Last Post: 08-07-2007, 06:33 PM -
Hard Token Management Framework 1.0_Beta1
By levent in forum Java SoftwareReplies: 0Last Post: 08-07-2007, 04:26 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks