Results 1 to 3 of 3
  1. #1
    asterix350z is offline Member
    Join Date
    Jul 2007
    Posts
    1
    Rep Power
    0

    Default 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

  2. #2
    vortex is offline Member
    Join Date
    Dec 2007
    Posts
    5
    Rep Power
    0

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

  3. #3
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    Test Strings for equality with the equals method
    instead of the == operator.
    Java Code:
    String s = "stop";
    // Does s == "stop"?
    System.out.println("s == \"stop\"      = " + (s == "stop"));
    // Does s equal "stop"?
    System.out.println("s.equals(\"stop\") = " + s.equals("stop"));

Similar Threads

  1. Hello, first time here.
    By ludragon in forum Introductions
    Replies: 2
    Last Post: 01-03-2008, 05:03 AM
  2. help with dates and time
    By osval in forum New To Java
    Replies: 3
    Last Post: 12-12-2007, 12:41 PM
  3. Time method
    By carderne in forum New To Java
    Replies: 5
    Last Post: 11-05-2007, 09:34 AM
  4. DataObject with the time given by me
    By garinapavan in forum New To Java
    Replies: 2
    Last Post: 08-07-2007, 06:33 PM
  5. Hard Token Management Framework 1.0_Beta1
    By levent in forum Java Software
    Replies: 0
    Last Post: 08-07-2007, 04:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •