Question

Code a complete Java program for the following payroll application: First, hard code the following data...

Code a complete Java program for the following payroll application:

First, hard code the following data for the object ‘Employee’ into 4 separate arrays:

SSN: 478936762, 120981098, 344219081, 390846789, 345618902, 344090917

First name      : Robert, Thomas, Tim, Lee, Young, Ropal

Last name       : Donal, Cook, Safrin, Matlo, Wang, Kishal

Hourly rate     : 12.75, 29.12, 34.25, 9.45,   20.95, 45.10

Hours worked: 45,        40,        39,       20,      44,        10

These 4 arrays must be declared inside the class and not within any method.

Also, declare a 5th array that will store the gross salaries of all har coded employees.

Steps:

-Code a menu in a method with the following options:

-1-Display all employees

-2-Search for an employee by SSN

-3-Display the employee record with the largest gross salary

-4-Display the employee record with the smallest gross salary

-5-Quit program

-Code a method that calculate the gross salaries for all employees (this method should be called earlier).

-Code a method that display a given employee record.

-Code a method that search for a given employee (when found you need to call the display method)

-Code a method that determine the max salary

-Code a method that determines the smallest salary.

The overall design is up to you, but do consider the following:

-is the SSN a String or an int?

-option 3 and 4 should not be enabled if the salary was not calculated first.

-Implement all checks and control (i.e. accept only valid options in the menu).

-Code a switch…case instead of the if..else

-Of course this program needs to repeat until user decides to quit.

Xtra credits:

-increase the size of all arrays to 100…in this case only the first 6 entries are filled still.

-add an option to the menu (i.e. get an employee) a new employee data will be added at the end of a given array (don’t forget to keep a count of how any entered so far)

-Code a method that calculate and displays the total payroll for all employees..but, of course, you need to tally all salaries first

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

class Employee{

    static int[] SSN = new int[100];
    static String[][] name = new String[100][2];
    static double[] h_rate = new double[100];
    static int[] h_worked = new int[100];
    static double[] gross = new double[100];

  
  
    static int tot_emp = 6;
  
    static void initial_values(){
  
    SSN[0] = 478936762;
    SSN[1] = 120981098;
    SSN[2] = 344219081;
    SSN[3] = 390846789;
    SSN[4] = 345618902;
    SSN[5] = 344090917;
  
    name[0][0] = "Robert";
    name[0][1] = "Donal";
  
    name[1][0] = "Thomas";
    name[1][1] = "Cook";
  
    name[2][0] = "Tim";
    name[2][1] = "Safrin";
  
    name[3][0] = "Lee";
    name[3][1] = "Matlo";
  
    name[4][0] = "Young";
    name[4][1] = "Wang";
  
    name[5][0] = "Ropal";
    name[5][1] = "Kishal";
  
    h_rate[0] = 12.75;
    h_rate[1] = 29.12;
    h_rate[2] = 34.25;
    h_rate[3] = 9.45;
    h_rate[4] = 20.95;
    h_rate[5] = 45.10;
  
    h_worked[0] = 45;
    h_worked[1] = 40;
    h_worked[2] = 39;
    h_worked[3] = 20;
    h_worked[4] = 44;
    h_worked[5] = 10;
  
    //calculate gross salary
    for (int i = 0;i<tot_emp;i++)
   {
      gross[i] = h_rate[i] * h_worked[i];
   }
  
    }

    static void func1(){

   System.out.println("All Employees Detail");
  
   for (int i = 0;i<tot_emp;i++)
   {
       System.out.println("SSN "+SSN[i]+" Employee Name "+name[i][0]+" "+name[i][1]+ " Hourly Rate: "+h_rate[i]+" Hours Worked "+h_worked[i]+ " Gross Salary: "+ gross[i]);
   }

    }

    static void func2(){
   System.out.println("Enter SSN to search");
  
   Scanner in = new Scanner(System.in);
   int ssn_search = in.nextInt();
   int found = 0;
  
   for (int i = 0;i<tot_emp;i++)
   {
       if(ssn_search == SSN[i])
        {
          System.out.println("SSN "+SSN[i]+" Employee Name "+name[i][0]+" "+name[i][1]+ " Hourly Rate: "+h_rate[i]+" Hours Worked "+h_worked[i]+ " Gross Salary: "+ gross[i]);
          found = 1;
          break;
        }
   }

   if(found==0)
      System.out.println("The SSN doesn't exist");

    }

    static void func3(){
   System.out.println("Employee Record With Largest Salary:");
  
   double max = gross[0];
   int pos = 0;
   for(int i=1;i<tot_emp;i++)
   {
      if(max<gross[i])
      {
        max = gross[i];
        pos = i;
      }
   }
  
   System.out.println("SSN "+SSN[pos]+" Employee Name "+name[pos][0]+" "+name[pos][1]+ " Hourly Rate: "+h_rate[pos]+" Hours Worked "+h_worked[pos]+ " Gross Salary: "+ gross[pos]);

    }

    static void func4(){
   System.out.println("Employee Record With Smallest Salary:");
  
   double min = gross[0];
   int pos = 0;
   for(int i=1;i<tot_emp;i++)
   {
      if(min>gross[i])
      {
        min = gross[i];
        pos = i;
      }
   }
  
   System.out.println("SSN "+SSN[pos]+" Employee Name "+name[pos][0]+" "+name[pos][1]+ " Hourly Rate: "+h_rate[pos]+" Hours Worked "+h_worked[pos]+ " Gross Salary: "+ gross[pos]);


    }
  
    static void func5(){
       System.out.println("Enter Info for New Employee");
       Scanner in = new Scanner(System.in);
      
      
       System.out.println("Enter SSN of new Employee");
       SSN[tot_emp] = in.nextInt();
       in.nextLine();   //to remove extra newline character in buffer
      
       System.out.println("Enter First Name of new Employee");
       name[tot_emp][0] = in.nextLine();
      
       System.out.println("Enter Last Name of new Employee");
       name[tot_emp][1] = in.nextLine();
      
       System.out.println("Enter Hourly Rate of new Employee");
       h_rate[tot_emp] = in.nextDouble();
      
       System.out.println("Enter Hours Worked of New Employee");
       h_worked[tot_emp] = in.nextInt();
      
       //calculate gross for new employee
       gross[tot_emp] = h_rate[tot_emp] * h_worked[tot_emp];
              
       tot_emp++;
    }

    static void func6(){
  
   System.out.println("Press any key to continue");
   Scanner in = new Scanner(System.in);
   String choice = in.nextLine();
   System.out.println("Bye!!!");
   System.exit(0);

    }


    public static void main(String args[]){

   int choice;
  
   initial_values();
  
   while(true){
  
        System.out.println("---------------------------------");
        System.out.println();
        System.out.println();
        System.out.println();
        System.out.println();
        System.out.println("1-Display all Employees");
        System.out.println("2-Search for an Employee by SSN");
        System.out.println("3-Display the employee record with largest gross salary ");
        System.out.println("4-Display the employee record with lowest salary");
        System.out.println("5-Add a new employee");
        System.out.println("6-Quit");
        System.out.println();
        System.out.println();
        System.out.println();
        System.out.println();
        System.out.println("Enter your choice");

        Scanner in = new Scanner(System.in);
        choice = in.nextInt();

        switch(choice){

        case 1:
       func1();
       break;
        case 2:
       func2();
       break;

        case 3:
       func3();
       break;

        case 4:
       func4();
       break;
      
        case 5:
             func5();
             break;


        case 6:
       func6();
       break;
        default:
       System.out.println("Enter Correct Choice");
        }

   }

    }

}

Add a comment
Know the answer?
Add Answer to:
Code a complete Java program for the following payroll application: First, hard code the following data...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a Java application with a class name of Payroll, for the “Travel Agency”, that willCalculate...

    Write a Java application with a class name of Payroll, for the “Travel Agency”, that willCalculate the weekly paycheck for both Salaried and Hourly employees. Salaried employees will be paid 1/52 of their annual pay minus 18% withheld for federal and state taxes, as well as 4% for retirement pension. Salaried employees do not collect overtime pay. There are two types of Hourly employees; permanent employees and temporary weekly employees. •Permanent weekly employees will be paid their hourly rate minus...

  • Write a C++ menu driven Payroll program. Must be user friendly.   Menu 1. Check data file  ...

    Write a C++ menu driven Payroll program. Must be user friendly.   Menu 1. Check data file   2. Read Data file 3. Process payroll for one employee 4. Process payroll for all employees 5. Print out to a text or an HTML file 6. Exit You must use the following Payroll classes, structures, pointers, arrays, enum, vector, recursive, advance file I/O, STL, iterators and containers. The program to process an input file below to calculate tax of 28% and output it...

  • Write a program that stores the following data in a tuple: 54,76,32,14,29,12,64,97,50,86,43,12 The program needs to...

    Write a program that stores the following data in a tuple: 54,76,32,14,29,12,64,97,50,86,43,12 The program needs to display a menu to the user, with the following 4 options: 1 – Display minimum 2 – Display maximum 3 – Display total 4 – Display average 5 – Quit Make your program loop back to this menu until the user chooses option 5. Write code for all 4 other menu choices using the python code and screenshot the python code for me. many...

  • Requesting help with the following C Program: DESIGN and IMPLEMENT a menu driven program that uses...

    Requesting help with the following C Program: DESIGN and IMPLEMENT a menu driven program that uses the following menu and can perform all menu items: Enter a payroll record for one person Display all paycheck stubs Display total gross payroll from all pay records. Quit program The program will reuse the DATE struct from the previous assignment.  You should also copy in the functions relating to a DATE. The program will create a PAYRECORD struct with the following fields: typedef struct...

  • in C++ Write a program which uses the following arrays: empID: An array of 7 integers...

    in C++ Write a program which uses the following arrays: empID: An array of 7 integers to hold employee identification numbers. The array should be initialized with the following values: 1, 2, 3, 4, 5, 6, 7. Hours: an array of seven integers to hold the number of hours worked by each employee. payRate: an array of seven doubles to hold each employee’s hourly pay rate. Wages: an array of seven doubles to hold each employee’s gross salary. The program...

  • using java Program: Please read the complete prompt before going into coding. Write a program that...

    using java Program: Please read the complete prompt before going into coding. Write a program that handles the gradebook for the instructor. You must use a 2D array when storing the gradebook. The student ID as well as all grades should be of type int. To make the test process easy, generate the grade with random numbers. For this purpose, create a method that asks the user to enter how many students there are in the classroom. Then, in each...

  • How would I do this problem? Write a C++ menu driven Payroll program. Must be user...

    How would I do this problem? Write a C++ menu driven Payroll program. Must be user friendly.   Menu 1. Check data file   2. Read Data file 3. Process payroll for one employee 4. Process payroll for all employees 5. Print out to a text or an HTML file 6. Exit You must use the following Payroll classes, structures, pointers, arrays, enum, vector, recursive, advance file I/O, STL, template, iterators and containers. The program to process an input file below to...

  • Java program. Code the following interfaces, implement them, and use the interface as a parameter, respectively:...

    Java program. Code the following interfaces, implement them, and use the interface as a parameter, respectively: a. An interface called Printable with a void print() method. b. An interface called EmployeeType with FACULTY and CLASSIFIED integer data. The value of FACULTY is 1 and CLASSIFIED is 2. a. A class called Employee to implement the two interfaces. Its constructor will initialize three instance data as name, employeeType, and salary. Implementation of method print() will display name, employeeType, and salary; salary...

  • Java Programing Code only Ragged Array Assignment Outcome: Student will demonstrate the ability to create and...

    Java Programing Code only Ragged Array Assignment Outcome: Student will demonstrate the ability to create and use a 2D array Student will demonstrate the ability to create and use a jagged array Student will demonstrate the ability to design a menu system Student will demonstrate the ability to think Program Specifications: Write a program that does the following: Uses a menu system Creates an array with less than 25 rows and greater than 5 rows and an unknown number of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT