Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.82 KB | None | 0 0
  1. //Emiris Germosen
  2. //Prof. F. Aljamal
  3. //CSC-117-02
  4. //Due Date:
  5. /* writing a java program to create a payroll report*/
  6.  
  7. import java.util.Scanner;
  8. public class PayRoll2
  9. {
  10.    public static void main(String [] args)
  11.    {
  12.    
  13.  
  14.       //declaring scanner
  15.       Scanner KB=new Scanner (System.in);
  16.      
  17.       //declaring variables
  18.       String firstname, lastname;
  19.       char mi, repeat;
  20.       final double stateTax= 0.06;
  21.       final double fedTax= 0.12;
  22.       final double unionfee= 0.01;
  23.       double  hrs=0.0, rate=0.0 ,net=0.0, average=0.0;
  24.       double  grossIncome, stax, ftax,ufee;
  25.       double overtime=0.0 ;
  26.       int counter = 0;
  27.      
  28.       //variables for counters
  29.        double tgross =0.0, tnet= 0.0;
  30.        double agross= 0.0, anet= 0.0;
  31.      
  32.      
  33.      
  34.      
  35.      
  36.          
  37.          
  38.          //loop to control the report
  39.          System.out.println("Enter y or Y to start");
  40.          repeat= KB.next().charAt(0);
  41.          
  42.          while (repeat == 'y'|| repeat == 'Y')
  43.          
  44.             {
  45.            
  46.            
  47.          
  48.                    System.out.println("enter middle initial" );
  49.                    mi=KB.next().charAt(0);
  50.                    KB.nextLine();
  51.                    
  52.                    System.out.println("enter employee's first name");
  53.                    firstname=KB.nextLine();
  54.                    
  55.    
  56.                    System.out.println("enter employee's last name");
  57.                    lastname= KB.nextLine();
  58.                    
  59.                  
  60.                    System.out.println("how many hours did the employee worked? ");
  61.                    hrs=KB.nextDouble();
  62.                    KB.nextLine();
  63.                                         //validating the input
  64.                    while (hrs <0 || hrs >=60)
  65.                    {
  66.                    
  67.                      System.out.println("Hours must be between 0 and 60");
  68.                      hrs=KB.nextDouble();
  69.                      
  70.                    }
  71.                    
  72.                    System.out.println("Whats the employee rate per hour?");
  73.                       rate=KB.nextDouble();
  74.                       //validating the input
  75.                       while (rate <0 || rate >=50)
  76.                      {
  77.                      System.out.println("the maximun for the rate is $50.");
  78.                      System.out.println("Try again.");
  79.                      System.out.println("Whats the employee rate per hour?");
  80.                      rate=KB.nextDouble();
  81.                      }
  82.                      
  83.                      //calculations
  84.                      
  85.                      
  86.                     if (hrs >40)
  87.                      overtime = (hrs - 40) * rate * 1.5;
  88.                      else
  89.                      overtime = 0;
  90.                      
  91.                      grossIncome = (rate * hrs)+ overtime;//gross income
  92.                      stax=grossIncome * stateTax;
  93.                      ftax= grossIncome *fedTax;
  94.                      ufee= grossIncome * unionfee;
  95.                      net= grossIncome-(stateTax + fedTax + unionfee)+ overtime;
  96.                          counter ++;
  97.                      tgross+= grossIncome;
  98.                      agross= tgross/counter;
  99.                      
  100.                      
  101.                      
  102.                      
  103.                     //output
  104.                    System.out.printf("First Name: %s\n", firstname);
  105.                    System.out.printf("Middle Initial: %s\n", mi);
  106.                    System.out.printf("Last Name: %s\n", lastname);
  107.                    System.out.printf("Hours Worked: %2.2f\n", hrs);
  108.                    System.out.printf("Pay rate: $%2.2f\n", rate);
  109.                    System.out.printf("Gross Income: $%2.2f\n", grossIncome);
  110.                    System.out.printf("Overtime: $%2.2f\n", overtime);
  111.                    System.out.printf("State Tax: $%2.2f\n", stax);
  112.                    System.out.printf("Federal Tax: $%2.2f\n", ftax);
  113.                    System.out.printf("Union Fee: $%2.2f\n", ufee);
  114.                    System.out.printf("Net: $%2.2f\n", net);
  115.                    System.out.println("====================");
  116.  
  117.                                
  118.               //accumulator
  119.                  
  120.                
  121.                      
  122.                      
  123.                                      
  124.  
  125.                    
  126.                    System.out.printf("The program ran %d\n",counter,"times");
  127.                    System.out.print("Enter Y o y to repeat");
  128.                    repeat=KB.next().charAt(0);
  129.  
  130.                              
  131.           }
  132.                              System.out.printf("Total Gross for all employees is: $%2.2f\n", tgross);
  133.                    System.out.printf("Average Gross for all employee is: $%2.2f\n ", agross);
  134.            
  135.          
  136.    }    
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement