Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Payroll Program Only Returning Value Of 0

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Thanked 0 Times in 0 Posts

    Default Payroll Program Only Returning Value Of 0

    Hi, for some reason I'm getting a value of 0 as my output.
    import java.util.Scanner;	//Needed for scanner class.
    public class Payroll{
    	private String EmployeeName;
    	private int IDnumber;
    	private double HourlyPayRate;
    	private double HoursWorked;
    	private double GrossPay;
    		@param Name The name to store in EmployeeName.
    		@param ID The ID to store in Employee ID number.
    	public Payroll(String Name, int ID)
    		EmployeeName = Name;
    		IDnumber = ID;
    	public String getEmployeeName()
    		return EmployeeName;
    	public int getIDnumber()
    		return IDnumber;
    	public void setHourlyPayRate(double HourlyRate)
    		HourlyPayRate = HourlyRate;
    	public double getHourlyPayRate()
    		return HourlyPayRate;
    	public void setHoursWorked(double hoursWorked)
    		HoursWorked = hoursWorked;
    	public double getHoursWorked()
    		return HoursWorked;
    	public double getGrossPay()
    		return HourlyPayRate * HoursWorked;

    import java.util.Scanner;	//Needed for Scanner class.
    public class PayRollTest
    public static void main(String[] args){
    		String EmployeeName;
    		int IDnumber;
    		double HoursWorked;
    		double HourlyPayRate;
    		double GrossPay;
    		//Create a Scanner object for keyboard input.
    		Scanner keyboard = new Scanner(System.in);
    		//Get the employee's name.
    		System.out.println("Enter an employee's name: ");
    		EmployeeName = keyboard.nextLine();
    		//Get the employee's ID.
    		System.out.println("Enter the employee's ID " );
    		IDnumber = keyboard.nextInt();
    		//Get the number of hours worked by the employee.
    		//Get the hourly pay rate of the employee.
    		System.out.println("Enter the hourly pay rate for this employee: ");
    		HourlyPayRate = keyboard.nextDouble();
    		System.out.println("Enter the number of hours worked: ");
    		//Create a payroll object, passing EmployeeName and IDnumber
    		// as arguments to the constructor.
    		Payroll pay = new Payroll(EmployeeName, IDnumber);
    		//Get the Gross Pay of the employee.
    		System.out.println("The gross pay of " + EmployeeName + " is: $" + pay.getGrossPay());

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Eastern Florida
    Thanked 2,416 Times in 2,369 Posts

    Default Re: Payroll Program Only Returning Value Of 0

    Please copy the contents of the command prompt window from when you execute the program that shows the input and the output. Add come comments showing what is wrong with output and show what the output should be.

    Try debugging the code by adding a println statement in the getGrossPay() method that prints out all the values of all the variables used in the method to compute the gross pay.
    See if their values are correct.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Program returning wrong values.
    By cam25 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 11th, 2012, 11:59 PM
  2. Trouble with Java payroll program
    By Shawn Wray in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 4th, 2012, 12:57 AM
  3. [SOLVED] Please help me with this payroll program
    By Leprechaun_hunter in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 14th, 2011, 06:47 PM
  4. Program not returning expected value.
    By adidez in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 2nd, 2011, 05:16 AM
  5. [SOLVED] Java Beginner: Help with methods and returning values (hailstone program)
    By alf in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 14th, 2010, 06:28 PM