//  Scott DeRuiter 9/22/2002
//  Paycheck.java
//  This program will calculate a paycheck from information
//  entered by the user.
//  7/15/2011 - Greenstein: Changed TextReader to Scanner

import java.util.Scanner;

public class Paycheck   
{
	public static void main ( String [] args )   
	{

		String name = new String("");
		int hours = 0;
		double hourlywage = 0.0;
		double taxrate = 0.0;
		Scanner console = new Scanner ( System.in );
		double subtotal, tax, takehome = 0.0;

		System.out.print ( "\n\n\nEnter your full name                          ->  " );
		name = console.nextLine ( );
		System.out.print ( "\nEnter hours worked this week (an integer)     ->  " );
		hours = console.nextInt ( );
		System.out.print ( "\nEnter your hourly wage (a double)             ->  " );
		hourlywage = console.nextDouble ( );
		System.out.print ( "\nEnter the tax rate as a percentage (a double) ->  " );
		taxrate = console.nextDouble ( );

		System.out.println ( "\n\n\nCongratulations!  " + name );
		System.out.println ( "\nHere is your paycheck:" );
		subtotal = hours * hourlywage;
		tax = subtotal * taxrate / 100.0;
		takehome = subtotal - tax;
		System.out.println ( "\nHours     :            " + Format.right ( hours, 20 ) );
		System.out.println ( "\nRate      :            " + Format.right ( hourlywage, 20, 2 ) );
		System.out.println ( "\nSubtotal  :            " + Format.right ( subtotal, 20, 2 ) );
		System.out.println ( "\nTax       :            " + Format.right ( tax, 20, 2 ) );
		System.out.println ( "\nTake Home :            " + Format.right ( takehome, 20, 2 ) );
	}
}

Back to Lesson 2 Examples

Back to Java Main Page