Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE HELP 1 2 import java.util.Scanner; 3 import java.text.NumberFormat; 4 5 p

ID: 3772577 • Letter: P

Question

PLEASE HELP

  1
2 import java.util.Scanner;
3 import java.text.NumberFormat;
4
5 public class Employee
6 {
7
8 //class constants
9
10
11 //class variable
12 private String name;
13 private int IdNumber;
14 private double HoursWorked;
15 private double HourlyRate;
16 private double GrossPay;
17
18 //*******************************************************************************************/
19 //Method Name : Employee(constructor)
20 //Author : Daniel Williams
21 //Due Date : December 14, 2015
22 //Course/Section : CSC 111
23 //Program Description: This constructor will intialize the instance data
24 //to values passed in via the parameter list.
25 //
26 // BEGIN Employee
27 // initialize all instance data
28 // END Employee
29 //**********************************************************************************************/
30
31 public Employee( String inName, int inIdNumber, double inHoursWorked, double inHourlyRate)
32 {
33 //Initialize all instance data
34 name = inName;
35 IdNumber = inIdNumber;
36 HoursWorked = inHoursWorked;
37 HourlyRate = inHourlyRate;
38
39
40 }//end constructor
41
42 /*********************************************************************************************/
43 //Method Name : Calculate Pay
44 //Author : Daniel Williams
45 //Due Date : December 14, 2015
46 //Course/Section : CSC 111
47 //Program Description: This constructor will calculate the pay
48 //
49 // BEGIN calculatePay
50 // Calculate Pay
51 // END calculatePay
52 //**********************************************************************************************/
53
54 public void calculatePay()
55 {
56
57 //local constants
58
59 //local variables
60
61 //***********************************************************************************************/
62
63 //Calculate Pay
64 if(HoursWorked <= 40)
65 GrossPay = HourlyRate * HoursWorked;
66 else if (HoursWorked <= 60)
67 GrossPay = 40 * HourlyRate + HourlyRate * 1.50 * (HoursWorked - 40);
68 else
69 GrossPay = HourlyRate + 20 * 1.20 * HourlyRate + HourlyRate * 2 * (HoursWorked - 60);
70 }
71
72 //*********************************************************************************************/
73 //Method Name : String toString
74 //Author : Daniel Williams
75 //Due Date : December 14, 2015
76 //Course/Section : CSC 111
77 //Program Description: This constructor will intialize the instance data
78 //to values passed in via the parameter list.
79 //
80 // BEGIN toString
81 // Output String
82 // END toString
83 //**********************************************************************************************/
84
85 public String toString()
86 {
87
88 //local constants
89
90 //local variables
91
92 NumberFormat fmt = NumberFormat.getCurrencyInstance();
93
94 //***********************************************************************************************/
95
96 //Output String
97 return "Employeename " + name + " IdNumber :" +
98 IdNumber + " HoursWorked :" + HoursWorked +
99 " HourlyRate :" + fmt.format (HourlyRate)
100 + " GrossPay :" + fmt.format(GrossPay);
101 }
102 }

Write a Java application that will allow the user to calculate the gross wages of several employees using arrays of objects. It will incorporate most of the structures that we have studied in class. There will be two classes and a driver program. The two classes are an Employee class and a Sales Person class. The data members of the Employee class are name, 4 digit id number, hours worked, hourly rate and gross pay. The employee data will be input by the user by means of the constructor. There is a minimum of three Employee objects in the array. There is a method that will calculate the gross wages for each employee using the nested if else statements of an earlier program to deal with overtime issues. The data members of the Sales Person class are name, 4 digit id number, base salary, total sales and gross pay. The Sales person data will also be input by using constructor. The gross pay of the Sales Person will be based upon their weekly salary and commission. If total sales are less than or equal to $1000, the commission is 15% with 20% on sales between S1000 and S2000 and 25% on the sales over $2000. Both classes will have a toString method for output. There is a static menu method that will print the possible choices the user may make in manipulating the data and a switch that will process the choice. It will also calculate the total payroll for the week. The output will be in tabular form with a heading for name, id number (leading zeros) and the total weekly payroll. A repetition structure will allow for processing another tabular form with a heading for name, id number (leading zeros), gross pay gross pay ing another department. Menu Method: Patty's Payroll Progranm Please choose from the following 1. Input Employee Data 2. Input Sales Person Data 3. Compute Total Payroll 4. Print Report

Explanation / Answer

import java.util.Scanner;
import java.text.NumberFormat;

public class Employee {

   // class constants

   // class variable
   private String name;
   private int IdNumber;
   private double HoursWorked;
   private double HourlyRate;
   private double GrossPay;

   // *******************************************************************************************/
   // Method Name : Employee(constructor)
   // Author : Daniel Williams
   // Due Date : December 14, 2015
   // Course/Section : CSC 111
   // Program Description: This constructor will intialize the instance data
   // to values passed in via the parameter list.
   //
   // BEGIN Employee
   // initialize all instance data
   // END Employee
   // **********************************************************************************************/

   public Employee(String inName, int inIdNumber, double inHoursWorked,
           double inHourlyRate) {
       // Initialize all instance data
       name = inName;
       IdNumber = inIdNumber;
       HoursWorked = inHoursWorked;
       HourlyRate = inHourlyRate;

   }// end constructor

   /*********************************************************************************************/
   // Method Name : Calculate Pay
   // Author : Daniel Williams
   // Due Date : December 14, 2015
   // Course/Section : CSC 111
   // Program Description: This constructor will calculate the pay
   //
   // BEGIN calculatePay
   // Calculate Pay
   // END calculatePay
   // **********************************************************************************************/

   public void calculatePay() {

       // local constants

       // local variables

       // ***********************************************************************************************/

       // Calculate Pay
       if (HoursWorked <= 40)
           GrossPay = HourlyRate * HoursWorked;
       else if (HoursWorked <= 60)
           GrossPay = 40 * HourlyRate + HourlyRate * 1.50 * (HoursWorked - 40);
       else
           GrossPay = HourlyRate + 20 * 1.20 * HourlyRate + HourlyRate * 2
                   * (HoursWorked - 60);
   }

   // *********************************************************************************************/
   // Method Name : String toString
   // Author : Daniel Williams
   // Due Date : December 14, 2015
   // Course/Section : CSC 111
   // Program Description: This constructor will intialize the instance data
   // to values passed in via the parameter list.
   //
   // BEGIN toString
   // Output String
   // END toString
   // **********************************************************************************************/

   public String toString() {

       // local constants

       // local variables

       NumberFormat fmt = NumberFormat.getCurrencyInstance();

       // ***********************************************************************************************/

       // Output String
       return "Employeename " + name + " IdNumber :" + IdNumber
               + " HoursWorked :" + HoursWorked + " HourlyRate :"
               + fmt.format(HourlyRate) + " GrossPay :"
               + fmt.format(GrossPay);
   }

   public static void main(String[] args) {

       Employee employee[] = new Employee[3];
       Scanner scanner;
       try {
           scanner = new Scanner(System.in);
           for (int i = 0; i < 3; i++) {
               System.out.print("Enter Name:");
               String name = scanner.next();
               System.out.print("Enter Id Number:");
               int IdNumber = scanner.nextInt();
               ;
               System.out.print("Enter Hours Worked:");
               double HoursWorked = scanner.nextDouble();
               System.out.print("Enter Hourly Rate:");
               double HourlyRate = scanner.nextDouble();
               ;
               System.out.print("Enter Gross Pay:");
               double GrossPay = scanner.nextDouble();
               employee[i] = new Employee(name, IdNumber, HoursWorked,
                       HourlyRate);

           }

           for (int i = 0; i < 3; i++) {
               employee[i].calculatePay();
               employee[i].toString();

           }

       } catch (Exception e) {
           // TODO: handle exception
       }

   }
}

/**
* @author Srinivas Palli
*
*/
public class SalesPerson {

   private String name;
   private int idNumber;
   private double baseSalary;
   private double totalSales;
   private double grossPay;

   /**
   * @param name
   * @param idNumber
   * @param baseSalary
   * @param totalSales
   */
   public SalesPerson(String name, int idNumber, double baseSalary,
           double totalSales) {
       super();
       this.name = name;
       this.idNumber = idNumber;
       this.baseSalary = baseSalary;
       this.totalSales = totalSales;
   }

   /**
   * caliculatePay() is used caliculate the gross pay based on the total sales
   * of the sales Person
   */
   public void calculatePay() {

       if (totalSales < 1000) {
           grossPay = baseSalary * (15 / 100);

       } else if (totalSales >= 1000 && totalSales <= 2000) {
           grossPay = baseSalary * (20 / 100);

       } else if (totalSales > 2000) {
           grossPay = baseSalary * (25 / 100);
       }
   }

   /* (non-Javadoc)
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return "SalesPerson [name=" + name + ", idNumber=" + idNumber
               + ", baseSalary=" + baseSalary + ", totalSales=" + totalSales
               + ", grossPay=" + grossPay + "]";
   }
  
  

}

import java.util.Scanner;

/**
* @author Srinivas Palli
*
*/
public class PattyPayrollTest {
   public static void main(String[] args) {
       try {
           Employee employees[] = new Employee[3];
           SalesPerson salesPersons[] = new SalesPerson[3];
           int empCount = 0, salesCount = 0;
           Scanner scanner = new Scanner(System.in);

           System.out.println("Patty's Payroll Program");
           System.out.println("Please choose from the following");

           do {

               System.out.println("1. Input Employee Data");
               System.out.println("2. Input Sales Person Data");
               System.out.println("3. Compute Total Payroll");
               System.out.println("4. Print Report");
               System.out.println("5. Exit");
               System.out.print("Enter your choice:");
               int ch = scanner.nextInt();
               switch (ch) {
               case 1: {
                   System.out.print("Enter Name:");
                   String name = scanner.next();
                   System.out.print("Enter Id Number:");
                   int IdNumber = scanner.nextInt();

                   System.out.print("Enter Hours Worked:");
                   double HoursWorked = scanner.nextDouble();
                   System.out.print("Enter Hourly Rate:");
                   double HourlyRate = scanner.nextDouble();
                   employees[empCount] = new Employee(name, IdNumber,
                           HoursWorked, HourlyRate);
                   empCount++;
                   break;
               }
               case 2: {
                   System.out.print("Enter Name:");
                   String name = scanner.next();
                   System.out.print("Enter Id Number:");
                   int IdNumber = scanner.nextInt();
                   System.out.print("Enter Base Salary:");
                   double baseSalary = scanner.nextDouble();
                   System.out.print("Enter Total Sales:");
                   double totalSales = scanner.nextDouble();
                   salesPersons[salesCount] = new SalesPerson(name, IdNumber,
                           baseSalary, totalSales);
                   salesCount++;
                   break;
               }
               case 3: {
                   for (int i = 0; i < empCount; i++) {
                       employees[i].calculatePay();

                   }

                   for (int i = 0; i < salesCount; i++) {
                       salesPersons[i].calculatePay();

                   }
                   break;
               }
               case 4: {
                   System.out.println(" Employees Data:");

                   for (int i = 0; i < empCount; i++) {
                       System.out.println(employees[i].toString());

                   }
                   System.out.println(" Sales Persons Data:");
                   for (int i = 0; i < salesCount; i++) {
                       System.out.println(salesPersons[i].toString());

                   }

                   break;
               }
               case 5: {

                   break;
               }

               default:
                   break;
               }
               if (ch == 5) {
                   break;
               }

           } while (true);
           scanner.close();
       } catch (Exception e) {
           // TODO: handle exception
       } finally {

       }
   }
}

OUTPUT:

Patty's Payroll Program
Please choose from the following
1. Input Employee Data
2. Input Sales Person Data
3. Compute Total Payroll
4. Print Report
5. Exit
Enter your choice:2
Enter Name:srinivas
Enter Id Number:3215
Enter Base Salary:583.5
Enter Total Sales:1526
1. Input Employee Data
2. Input Sales Person Data
3. Compute Total Payroll
4. Print Report
5. Exit
Enter your choice:1
Enter Name:Rajesh
Enter Id Number:8579
Enter Hours Worked:458
Enter Hourly Rate:658
1. Input Employee Data
2. Input Sales Person Data
3. Compute Total Payroll
4. Print Report
5. Exit
Enter your choice:3
1. Input Employee Data
2. Input Sales Person Data
3. Compute Total Payroll
4. Print Report
5. Exit
Enter your choice:4

Employees Data:
Employeename
Rajesh
IdNumber :8579
HoursWorked :458.0
HourlyRate :$658.00
GrossPay :$540,218.00

Sales Persons Data:
SalesPerson [name=srinivas, idNumber=3215, baseSalary=583.5, totalSales=1526.0, grossPay=0.0]
1. Input Employee Data
2. Input Sales Person Data
3. Compute Total Payroll
4. Print Report
5. Exit
Enter your choice:3
1. Input Employee Data
2. Input Sales Person Data
3. Compute Total Payroll
4. Print Report
5. Exit
Enter your choice:4

Employees Data:
Employeename
Rajesh
IdNumber :8579
HoursWorked :458.0
HourlyRate :$658.00
GrossPay :$540,218.00

Sales Persons Data:
SalesPerson [name=srinivas, idNumber=3215, baseSalary=583.5, totalSales=1526.0, grossPay=0.0]
1. Input Employee Data
2. Input Sales Person Data
3. Compute Total Payroll
4. Print Report
5. Exit
Enter your choice:5

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote