Results 1 to 3 of 3
  1. #1
    xgodx415 is offline Member
    Join Date
    Jul 2011
    Posts
    2
    Rep Power
    0

    Question Payroll program will not print decimals... could someone help?

    I am taking a Java coding class, and i pretty much have the code i need written out but it will not let me type decimals points Could anyone take a look at let me know where my error is?

    Java Code:
    import java.util.Scanner;
    
    public class Payroll2 {
    public static void main( String[] args ){
    Scanner input = new Scanner( System.in );
            {
    System.out.print ( "Enter employee name: " );
    String theName = input.nextLine();
     {
                }
    int hours;
    {
    	System.out.println("Enter hours worked:");
    	String line = input.nextLine();
    	hours = Integer.parseInt(line);
    	if(hours < 0)
    	System.out.println("number must be positive");
     }
    while(hours < 0);
    
    	int pay;
    	 do
     {
    	System.out.println("Enter hourly pay rate:");
    	String line = input.nextLine();
    	pay = Integer.parseInt(line);
    	if(pay < 0)
    	System.out.println("number must be positive");
                }
    while(pay < 0);
    	int week = hours * pay;
    	System.out.println("Total weekly pay is $");
    	System.out.println (week);
    }
    }
    }
    Last edited by Fubarable; 07-31-2011 at 11:07 PM. Reason: code tags added

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

    Default

    Moderation: code tags added to original post.

    To the OP: what do you mean by "it will not let me type decimals points"? Do you mean that you are trying to enter floating point numbers such as 12.45? If so, then you won't want to parse the number with Integer.parseInt(...) since that obviously expects an integer-like String. Perhaps you want to use a similar method found in the Double class?

    Also, please look at my link on how to use code tags in the forum. You'll find many more folks willing to read your code and help you if it is well formatted and readable. Much luck.

  3. #3
    xgodx415 is offline Member
    Join Date
    Jul 2011
    Posts
    2
    Rep Power
    0

    Default

    Thank you, Looking into double class as we speak. Thanks again

Similar Threads

  1. Payroll program.. School.. Help Please!
    By eddyb5 in forum New To Java
    Replies: 2
    Last Post: 06-05-2011, 05:49 PM
  2. payroll program 2
    By joshwey in forum New To Java
    Replies: 13
    Last Post: 05-13-2011, 09:27 AM
  3. Payroll program
    By bigley04 in forum Eclipse
    Replies: 7
    Last Post: 12-06-2010, 04:57 PM
  4. Need help ASAP with Payroll Program Part 2
    By arrech326 in forum New To Java
    Replies: 10
    Last Post: 11-17-2009, 10:17 PM
  5. Replies: 1
    Last Post: 07-02-2008, 01:58 PM

Tags for this Thread

Posting Permissions

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