Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.91 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 project
  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, averageNet=0.0, averageGross=0.0;
  24.       double  grossIncome=0.0, totalGross=0.0, totalNet=0.0;
  25.       double overtime=0.0;
  26.       int counter = 0;
  27.      
  28.      
  29.      
  30.          
  31.          
  32.          //loop to control the report
  33.          System.out.println("Enter y or Y to start");
  34.          repeat= KB.next().charAt(0);
  35.          
  36.          while (repeat == 'y'|| repeat == 'Y')
  37.          
  38.             {
  39.            
  40.            
  41.          
  42.                    System.out.println("enter middle initial" );
  43.                    mi=KB.next().charAt(0);
  44.                    KB.nextLine();
  45.                    
  46.                    System.out.println("enter employee's first name");
  47.                    firstname=KB.nextLine();
  48.                    
  49.    
  50.                    System.out.println("enter employee's last name");
  51.                    lastname= KB.nextLine();
  52.                    
  53.                  
  54.                    System.out.println("how many hours did the employee worked? ");
  55.                    hrs=KB.nextDouble();
  56.                    KB.nextLine();
  57.                                         //validating the input
  58.                    while (hrs <0 || hrs >=60)
  59.                    {
  60.                    
  61.                      System.out.println("Hours must be between 0 and 60");
  62.                      hrs=KB.nextDouble();
  63.                      
  64.                    }
  65.                    
  66.                    System.out.println("Whats the employee rate per hour?");
  67.                       rate=KB.nextDouble();
  68.                       //validating the input
  69.                       while (rate <0 || rate >=50)
  70.                      {
  71.                      System.out.println("the maximun for the rate is $50.");
  72.                      System.out.println("Try again.");
  73.                      System.out.println("Whats the employee rate per hour?");
  74.                      rate=KB.nextDouble();
  75.                      }
  76.                      
  77.                      
  78.                      //calculations
  79.                      if (hrs >40)
  80.                      overtime = (hrs - 40) * rate * 1.5;
  81.                      else
  82.                      overtime = 0;
  83.                      
  84.                      grossIncome = (rate * hrs)+ overtime;
  85.  
  86.                                          
  87.                      net = grossIncome-(stateTax + fedTax + unionfee)+ overtime;
  88.              
  89.                      counter ++;
  90.                      totalNet = net + net;
  91.                      averageNet = totalNet/counter;
  92.                      totalGross = grossIncome + grossIncome;
  93.                      averageGross = totalGross/counter;      
  94.                    
  95.  
  96.                    
  97.                    //output
  98.                    
  99.                    System.out.printf("First Name: %s\n", firstname);
  100.                    System.out.printf("Middle Initial: %s\n", mi);
  101.                    System.out.printf("Last Name: %s\n", lastname);
  102.                    System.out.printf("Hours Worked: %2.2f\n", hrs);
  103.                    System.out.printf("Pay rate: $%2.2f\n", rate);
  104.                    System.out.printf("Gross Income: $%2.2f\n", grossIncome);
  105.                    System.out.printf("Overtime: $%2.2f\n", overtime);
  106.                    System.out.printf("State Tax: $%2.2f\n", stateTax);
  107.                    System.out.printf("Federal Tax: $%2.2f\n", fedTax);
  108.                    System.out.printf("Union Fee: $%2.2f\n", unionfee);
  109.                    System.out.printf("Net: $%2.2f\n", net);
  110.  
  111.                                
  112.                    //accumulator
  113.                  
  114.                
  115.  
  116.                    
  117.  
  118.                    System.out.print("Enter Y o y to repeat");
  119.                    repeat=KB.next().charAt(0);
  120.  
  121.                              
  122.           }
  123.            System.out.println(counter);
  124.                             System.out.println("====================");
  125.                             System.out.printf("Total net of all employee is: $%2.2f\n ", totalNet);
  126.                    System.out.printf("Average net of all employee is: $%2.2f\n ", averageNet);
  127.                    
  128.                                                System.out.println("====================");
  129.                                                 System.out.printf("Total gross of all employee is: $%2.2f\n ", totalGross);
  130.                    System.out.printf("Average gross of all employee is: $%2.2f\n ", averageGross);
  131.    }    
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement