Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Emiris Germosen
- //Prof. F. Aljamal
- //CSC-117-02
- //Due Date:
- /* writing a java program to create a payroll report*/
- import java.util.Scanner;
- public class project
- {
- public static void main(String [] args)
- {
- //declaring scanner
- Scanner KB=new Scanner (System.in);
- //declaring variables
- String firstname, lastname;
- char mi, repeat;
- final double stateTax= 0.06;
- final double fedTax= 0.12;
- final double unionfee= 0.01;
- double hrs=0.0, rate=0.0 ,net=0.0, averageNet=0.0, averageGross=0.0;
- double grossIncome=0.0, totalGross=0.0, totalNet=0.0;
- double overtime=0.0;
- int counter = 0;
- //loop to control the report
- System.out.println("Enter y or Y to start");
- repeat= KB.next().charAt(0);
- while (repeat == 'y'|| repeat == 'Y')
- {
- System.out.println("enter middle initial" );
- mi=KB.next().charAt(0);
- KB.nextLine();
- System.out.println("enter employee's first name");
- firstname=KB.nextLine();
- System.out.println("enter employee's last name");
- lastname= KB.nextLine();
- System.out.println("how many hours did the employee worked? ");
- hrs=KB.nextDouble();
- KB.nextLine();
- //validating the input
- while (hrs <0 || hrs >=60)
- {
- System.out.println("Hours must be between 0 and 60");
- hrs=KB.nextDouble();
- }
- System.out.println("Whats the employee rate per hour?");
- rate=KB.nextDouble();
- //validating the input
- while (rate <0 || rate >=50)
- {
- System.out.println("the maximun for the rate is $50.");
- System.out.println("Try again.");
- System.out.println("Whats the employee rate per hour?");
- rate=KB.nextDouble();
- }
- //calculations
- if (hrs >40)
- overtime = (hrs - 40) * rate * 1.5;
- else
- overtime = 0;
- grossIncome = (rate * hrs)+ overtime;
- net = grossIncome-(stateTax + fedTax + unionfee)+ overtime;
- counter ++;
- totalNet = net + net;
- averageNet = totalNet/counter;
- totalGross = grossIncome + grossIncome;
- averageGross = totalGross/counter;
- //output
- System.out.printf("First Name: %s\n", firstname);
- System.out.printf("Middle Initial: %s\n", mi);
- System.out.printf("Last Name: %s\n", lastname);
- System.out.printf("Hours Worked: %2.2f\n", hrs);
- System.out.printf("Pay rate: $%2.2f\n", rate);
- System.out.printf("Gross Income: $%2.2f\n", grossIncome);
- System.out.printf("Overtime: $%2.2f\n", overtime);
- System.out.printf("State Tax: $%2.2f\n", stateTax);
- System.out.printf("Federal Tax: $%2.2f\n", fedTax);
- System.out.printf("Union Fee: $%2.2f\n", unionfee);
- System.out.printf("Net: $%2.2f\n", net);
- //accumulator
- System.out.print("Enter Y o y to repeat");
- repeat=KB.next().charAt(0);
- }
- System.out.println(counter);
- System.out.println("====================");
- System.out.printf("Total net of all employee is: $%2.2f\n ", totalNet);
- System.out.printf("Average net of all employee is: $%2.2f\n ", averageNet);
- System.out.println("====================");
- System.out.printf("Total gross of all employee is: $%2.2f\n ", totalGross);
- System.out.printf("Average gross of all employee is: $%2.2f\n ", averageGross);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement