Java Salary Calculator

Mountain State University Java Assignment

3.20 (Salary Calculator)

Develop a Java application that determines the gross pay for each of three employees. The company pays straight time for the first 40 hours worked by each employee and time and a half for all hours worked in excess of 40. You are given a list of the employees, their number of hours worked last week and their hourly rates. Your program should input this information for each employee, then determine and display the employee’s gross pay. Use the class Scanner to input the data.

Java Salary Calculator Source Code

java.util.Scanner; //initialize scanner

public class salaryCalculator // defines class name
{

public static void main( String[] args )
{

// create Scanner to obtain input from command window
Scanner input = new Scanner( System.in );

double hours; // number of hours worked input
double pay; // rate of hourly wage input
double overtime; // used to calculate overtime

// First input is for employee #1
System.out.print( "Enter the number of regular hours worked Jon Smith Worked "
); // prompt for user input
hours = input.nextDouble();

System.out.print( "Enter the number of overtime hours Jon Smith worked " ); //
prompt for user input
overtime = input.nextDouble();

System.out.print( "Enter the payrate of John Smith " ); // prompt for user input
pay = input.nextDouble();

if (overtime == 0 )

System.out.printf( "Gross pay for this John Smith is %.2f\n", hours * pay );

else
{

System.out.printf( "Gross pay for this John Smith is %.2f\n", (hours * pay) +
(overtime * (pay * 1.5)) );

}

// Second input is for employee #2
System.out.print( "Enter the number of regular hours worked Betty Jones Worked "
); // prompt for user input
hours = input.nextDouble();

System.out.print( "Enter the number of overtime hours Betty Jones worked " ); //
prompt for user input
overtime = input.nextDouble();

System.out.print( "Enter the payrate of Betty Jones " ); // prompt for user
input
pay = input.nextDouble();

if (overtime == 0 )

System.out.printf( "Gross pay for this Betty Jones is %.2f\n", hours * pay );

else
{

System.out.printf( "Gross pay for this Betty Jones is %.2f\n", (hours * pay) +
(overtime * (pay * 1.5)) );

}

// Third input is for employee #3
System.out.print( "Enter the number of regular hours worked LeMont Jordan Worked
" ); // prompt for user input
hours = input.nextDouble();

System.out.print( "Enter the number of overtime hours LeMont Jordan worked " );
// prompt for user input
overtime = input.nextDouble();

System.out.print( "Enter the payrate of LeMont Jordan " ); // prompt for user
input
pay = input.nextDouble();

if (overtime == 0 )

System.out.printf( "Gross pay for this LeMont Jordan is %.2f\n", hours * pay );

else
{

System.out.printf( "Gross pay for this Betty Jones is %.2f\n", (hours * pay) +
(overtime * (pay * 1.5)) );

}

} //end method main

} // end class salaryCalculator

0
  Related Posts