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

Note for all above User Defined Classes: • Provide appropriate validation code s

ID: 3685831 • Letter: N

Question

Note for all above User Defined Classes: • Provide appropriate validation code so the right values get populated in the instance variables. For example, the payrate should not be negative. • Make sure to provide JavaDoc style comments. Write a Java application (Client) program with a static method called generateEmployees( ) that returns a random list of 10 different types of Employee objects. You could either use an array or an ArrayList to store the employee objects that will be returned. Use a for loop to populate randomly different types of employee objects with some random data. You could possibly think a range of values like 1 – 4. If random value is 1, create a HourlyEmployee object with some randomly generated data, if 2, SalariedEmployee object with some random data and so on. I would leave it to your ingenuity to generate and populate these different Employee objects. As these objects are generated add them to your data structure (array or ArrayList that you are using). Finally the method returns this data structure. In the same application class, implement the main( ) method. Call the generateEmployees( ) static method and using a for loop to print the details of each of the employee along with their earnings on the output window.

Explanation / Answer

Please use the below piece of java code for your task:

EmployeeClient.java

import java.util.ArrayList;
import java.util.Random;
import java.text.DecimalFormat;

public class EmployeeClient{
   public static ArrayList<Employee> generateEmployees(){
       ArrayList<Employee> employees = new ArrayList<Employee>();
       Random random = new Random();
       for(int i = 0; i < 10; i++){
           switch(random.nextInt(4)){
               case 0:
                   employees.add(new SalariedEmployee("David", "Rice", Integer.toString(random.nextInt(10000000) + 10000000), random.nextDouble() * 100));
                   break;
               case 1:
                   employees.add(new CommissionEmployee("David", "Rice", Integer.toString(random.nextInt(10000000) + 10000000), random.nextDouble() * 1000, random.nextDouble()/10));
                   break;
               case 2:
                   employees.add(new BasePlusCommissionEmployee("David", "Rice", Integer.toString(random.nextInt(10000000) + 10000000), random.nextDouble() * 1000, random.nextDouble()/10, random.nextDouble() * 100));
                   break;
               case 3:
                   employees.add(new HourlyEmployee("David", "Rice", Integer.toString(random.nextInt(10000000) + 10000000), random.nextDouble() * 10, random.nextInt(60)));
                   break;
           }
       }
       return employees;
   }

   public static void main(String[] args){
       ArrayList<Employee> employees = generateEmployees();
       for (Employee e : employees){
           System.out.println(e.toString());
           System.out.println("Earnings: $" + new DecimalFormat("#.00").format(e.getEarnings()) + " ");
       }
   }
}

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