# Payroll Calculator Program

Page 1 of 1

## 7 Replies - 6254 Views - Last Post: 01 September 2014 - 08:20 PMRate Topic: 1 Votes //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=352964&amp;s=97fe7f50ed5ffe80c89c48e146269424&md5check=' + ipb.vars['secure_hash'], cur_rating: 1, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 lotionmerchant

• New D.I.C Head

Reputation: 0
• Posts: 3
• Joined: 01-September 14

# Payroll Calculator Program

Posted 01 September 2014 - 05:13 PM

Really not sure what i'm doing wrong. Works fine in my compiler but can't get the online submission site we use to accept it. Here's what I already have. Any help?
```import java.util.Scanner;

public class Payroll
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);

System.out.print("Enter employee's name: ");
String x1 = input.nextLine();

System.out.print("Enter number of hours worked in a week: ");
double x2 = input.nextDouble();

System.out.print("Enter hourly pay rate: ");
double x3 = input.nextDouble();

System.out.print("Enter federal tax withholding rate: ");
double x5 = input.nextDouble();

System.out.print("Enter state tax withholding rate: ");
double x7 = input.nextDouble();

double x4 = x2 * x3;
double x6 = x5 * x4;
double x8 = x7 * x4;
double x9 = x6 + x8;
double x10 = x4 - x9;

System.out.println("Employee Name : " + x1);
System.out.println("Hours Worked: " + x2);
System.out.println("Pay Rate: " + "\$" + x3);
System.out.println("Gross Pay: " + "\$" + x4);
System.out.println("Deductions:");
System.out.println("       Federal Withholding " + x5 + ": " + "\$" +x6);
System.out.println("       State Withholding " + x7 + ": " + "\$" + x8);
System.out.println("       Total Dedduction: " + "\$" + x9);
System.out.println("Net Pay: " + "\$" + x10);
}
}

```

Here was the prompt:
```Chapter 2 Exercise 25
PAYROLL.
(Financial application: payroll) Write a program  that reads the following information and prints a payroll statement :

Employee's name  (e.g., Smith)
Number of hours worked in a week (e.g., 10)
Hourly pay rate (e.g., 6.75)
Federal tax withholding rate (e.g., 20%)
State tax withholding rate (e.g., 9%)

INPUT and PROMPTS. The program  prompts for a single string  (the name ) with: "Enter employee's name : ". The it prompts for the hours, pay rate, federal and state witholding rates with these prompts: "Enter number of hours worked in a week: ", "Enter hourly pay rate: ", "Enter federal tax withholding rate: ", "Enter state tax withholding rate: ".

OUTPUT . The output  should be as follows:
Employee Name : x1
Hours Worked: x2
Pay Rate: x3
Gross Pay: x4
Deductions:
Federal Witholding (x5%): x6
State Witholding (x7%): x8
Total Dedduction: x9
Net Pay: x10
where the various place-holders x1. . . x10 are the quantities read in or calculated by the program . ALSO: monetary quantities must be preceded by a "\$" and be calculated rounded down to the nearest penny.

CLASS  NAMES. Your program  class  should be called Payroll

```

This post has been edited by macosxnerd101: 01 September 2014 - 05:17 PM
Reason for edit:: Renamed title to be more descriptive

Is This A Good Question/Topic? 0

## Replies To: Payroll Calculator Program

### #2 jon.kiparsky

• Beginner

Reputation: 11022
• Posts: 18,805
• Joined: 19-March 11

## Re: Payroll Calculator Program

Posted 01 September 2014 - 05:17 PM

Quote

ALSO: monetary quantities must be preceded by a "\$" and be calculated rounded down to the nearest penny.

I don't see you rounding down. Look into number formatting.

Does the submission system provide any feedback? If so, what is it saying?
Was This Post Helpful? 0

### #3 astonecipher

• Senior Systems Engineer

Reputation: 2490
• Posts: 9,974
• Joined: 03-December 12

## Re: Payroll Calculator Program

Posted 01 September 2014 - 05:21 PM

What online submission site do you use? Do they have documentation for using their api?
Was This Post Helpful? 0

### #4 lotionmerchant

• New D.I.C Head

Reputation: 0
• Posts: 3
• Joined: 01-September 14

## Re: Payroll Calculator Program

Posted 01 September 2014 - 05:25 PM

astonecipher, on 01 September 2014 - 05:21 PM, said:

What online submission site do you use? Do they have documentation for using their api?

We use MyProgrammingLab. I don't think so

jon.kiparsky, on 01 September 2014 - 05:17 PM, said:

Quote

ALSO: monetary quantities must be preceded by a "\$" and be calculated rounded down to the nearest penny.

I don't see you rounding down. Look into number formatting.

Does the submission system provide any feedback? If so, what is it saying?

Ahh okay, I'm not really sure how to do rounding but I'll research it real quick and see what I can find.

It doesn't give me any feedback, just says I have a logical error and says: "Exception java.util.NoSuchElementException occurred"
Was This Post Helpful? 0

### #5 astonecipher

• Senior Systems Engineer

Reputation: 2490
• Posts: 9,974
• Joined: 03-December 12

## Re: Payroll Calculator Program

Posted 01 September 2014 - 05:31 PM

I think I misunderstood your version of accept. I am thinking api interaction, I think yours is more of a code scanner.
Was This Post Helpful? 0

### #6 jon.kiparsky

• Beginner

Reputation: 11022
• Posts: 18,805
• Joined: 19-March 11

## Re: Payroll Calculator Program

Posted 01 September 2014 - 05:36 PM

lotionmerchant, on 01 September 2014 - 07:25 PM, said:

It doesn't give me any feedback, just says I have a logical error and says: "Exception java.util.NoSuchElementException occurred"

That would be feedback.

This exception is thrown by the Scanner's next methods if there is no element in the queue. See this blog entry for a likely explanation of the cause.

Docs for the Exception and the method where it's being thrown.
Was This Post Helpful? 0

### #7 lotionmerchant

• New D.I.C Head

Reputation: 0
• Posts: 3
• Joined: 01-September 14

## Re: Payroll Calculator Program

Posted 01 September 2014 - 07:33 PM

jon.kiparsky, on 01 September 2014 - 05:36 PM, said:

lotionmerchant, on 01 September 2014 - 07:25 PM, said:

It doesn't give me any feedback, just says I have a logical error and says: "Exception java.util.NoSuchElementException occurred"

That would be feedback. />

This exception is thrown by the Scanner's next methods if there is no element in the queue. See this blog entry for a likely explanation of the cause.

Docs for the Exception and the method where it's being thrown.

I'm still not getting it lol. I read that blog post and the other stuff you linked but I don't have a deep enough understanding of java yet to apply the knowledge they gave me
Was This Post Helpful? 0

### #8 jon.kiparsky

• Beginner

Reputation: 11022
• Posts: 18,805
• Joined: 19-March 11

## Re: Payroll Calculator Program

Posted 01 September 2014 - 08:20 PM

Hm. Since I can't see what you're submitting to, I suggest you talk to your instructor about the error. They'll be in a better position to help you on this one.
Was This Post Helpful? 0

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }