7 Replies - 6394 Views - Last Post: 01 September 2014 - 08:20 PM Rate Topic: *---- 1 Votes

#1 lotionmerchant   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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   User is offline

  • Beginner
  • member icon


Reputation: 11095
  • View blog
  • Posts: 18,982
  • 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   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2560
  • View blog
  • Posts: 10,277
  • 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   User is offline

  • New D.I.C Head

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

Re: Payroll Calculator Program

Posted 01 September 2014 - 05:25 PM

View Postastonecipher, 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 :/

View Postjon.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   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2560
  • View blog
  • Posts: 10,277
  • 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   User is offline

  • Beginner
  • member icon


Reputation: 11095
  • View blog
  • Posts: 18,982
  • Joined: 19-March 11

Re: Payroll Calculator Program

Posted 01 September 2014 - 05:36 PM

View Postlotionmerchant, 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   User is offline

  • New D.I.C Head

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

Re: Payroll Calculator Program

Posted 01 September 2014 - 07:33 PM

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

View Postlotionmerchant, 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   User is offline

  • Beginner
  • member icon


Reputation: 11095
  • View blog
  • Posts: 18,982
  • 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