Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Java Help - Payroll calculator

calculator

  • Please log in to reply
1 reply to this topic

#1 Rich_D

Rich_D

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 05 February 2012 - 01:55 PM

Hi all, I'm just starting out in Java and can't get this program to run correctly. It compiles fine, but seems to stop after the main method. Any help would be appreciated.

import java.io.*;
 import java.util.*;  //Contains Scanner class

public class PayCalculator  {

	private final static double OT_START  = 40.0;  // overtime starts after 40 hours
	private final static double OT_ADJUST = 0.5;   // overtime adjustment
	private final static double TAX       = 0.2;   // 20%


	public static void  main(String[]  args) {

		double hours;
		double rate;


    // Create a Scanner object to read input.
        Scanner keyboard = new Scanner(System.in);

    // Get the number of hours worked this week.
        System.out.print("Input Hours worked <1 week>\n--> ");
        hours = keyboard.nextDouble();

    //Get the user's hourly pay rate.
        System.out.print("Input hourly pay\n--> ");
        rate = keyboard.nextDouble();

          	}

	public static double calculateNetPay(double hours, double rate)
		{
		double hoursOT;
		double grossPay;
		double netPay;


		//Determine if Overtime pay is required and calculate based upon OT rates
		if (hours > OT_START)
		{
			hoursOT = hours - OT_START;
			grossPay = (hours * rate) + (hoursOT *(rate*(1+OT_ADJUST)));
			netPay = grossPay * TAX;

		System.out.println("Net Pay: $" + netPay);
    	System.out.println("Hours until overtime: " + OT_START);
		System.out.println("Overtime adjustment: 50.00%");
		System.out.println("Tax rate: 20.00%");

		}
		//If no OT calculate straight pay
		else
		{
			grossPay = hours * rate;
			netPay = grossPay * TAX;
		System.out.println("Net Pay: $" + netPay);
    	System.out.println("Hours until overtime: " + OT_START);
		System.out.println("Overtime adjustment: 50.00%");
		System.out.println("Tax rate: 20.00%");

			}

		return netPay;




		}




	}

  • 0

#2 gregwarner

gregwarner

    Obi Wan of Programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1586 posts
  • Location:Arkansas
  • Programming Language:C, Java, C++, C#, PHP, Transact-SQL

Posted 10 February 2012 - 08:43 AM

You never call the calculateNetPay() method in your main method. All you told it to do is scan two doubles from the console and quit.
  • 0

ti-99-sig.png
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download