Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2009
    Posts
    3
    Rep Power
    0

    Default Payroll output thingy...

    I'm working on a program for my CSCI class, on putting out a payroll printout that just displays on the screen. I have written the program about ten times already, and every time I go to view the final printout, the net pay section repeats itself....I need help...Please?

  2. #2
    Join Date
    Aug 2009
    Posts
    3
    Rep Power
    0

    Default

    Java Code:
    /**
     *
     * @author Austin
     */
    
    import java.util.Scanner;
    
    public class Exercise2_11 {
        public static void main(String[] args) {
            Scanner input = new Scanner(System.in);
    
            System.out.print("Enter employee's name: ");
                String string = input.next();
            System.out.print("Enter number of hours per week: ");
                double hours = input.nextDouble();
            System.out.print("Enter hourly pay rate: ");
                double payrate = input.nextDouble();
            System.out.print("Enter federal tax witholding rate: ");
                double fedtaxwithold = input.nextDouble();
            System.out.print("Enter state tax witholding rate: ");
                double statetaxwithold = input.nextDouble();
    
            double gross = hours * payrate;
            double fedtax = fedtaxwithold * gross;
            double statetax = statetaxwithold * gross;
            double deduc = statetax + fedtax;
            double salary = gross - deduc;
    
            System.out.print("Employee's name: " + string +
                             "\nHours per week: " + hours +
                             "\nHourly Rate: " + payrate +
                             "\nDeductions: " +
                             "\n   Federal Tax Witholdings: " + fedtaxwithold +
                             "\n   State Tax Witholdings: " + statetaxwithold +
                             "\n   Total Deductions: " + deduc +
                             "\nNet Pay: " + salary);
            
                
    
        }
    }
    Last edited by Fubarable; 08-25-2009 at 01:20 AM.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by ShadowUndertow View Post
    every time I go to view the final printout, the net pay section repeats itself.
    I don't see this happening when I run your code. The only suggestions I would make would be to display fedtax and statetax, not the witholdings, but that's a relatively minor quibble. That and to use code tags when posting code (I've added them to your code above).

    Also, consider calling input.nextLine() after scanning in any token that does not swallow the nextline characters. i.e.,
    Java Code:
        System.out.print("Enter employee's name: ");
        //String string = input.next();
        String string = input.nextLine(); // better
        System.out.print("Enter number of hours per week: ");
        double hours = input.nextDouble();
        input.nextLine(); // added
        System.out.print("Enter hourly pay rate: ");
        double payrate = input.nextDouble();
        input.nextLine(); // added
        System.out.print("Enter federal tax witholding rate: ");
        double fedtaxwithold = input.nextDouble();
        input.nextLine(); // added
        System.out.print("Enter state tax witholding rate: ");
        double statetaxwithold = input.nextDouble();
        input.nextLine(); // added
    Last edited by Fubarable; 08-25-2009 at 01:23 AM.

  4. #4
    Join Date
    Aug 2009
    Posts
    3
    Rep Power
    0

    Default

    Thanks, but I found out the problem. I was missing the ln qualifier after the print command in the last system output thing. Thanks though!

Similar Threads

  1. Payroll Project 1 Troubles
    By KiskaBaker in forum New To Java
    Replies: 3
    Last Post: 08-16-2009, 12:41 PM
  2. Java, output string, getting correct output? HELP!
    By computerboyo in forum New To Java
    Replies: 2
    Last Post: 02-25-2009, 11:44 PM
  3. Payroll Program exits at wrong time
    By jsand2 in forum Java Applets
    Replies: 13
    Last Post: 01-26-2009, 03:10 AM
  4. help for payroll project in java
    By mageshwari in forum New To Java
    Replies: 2
    Last Post: 04-09-2008, 02:46 AM
  5. Payroll Part 2, Java
    By lplopez92 in forum New To Java
    Replies: 2
    Last Post: 03-24-2008, 01:55 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
  •