A company has an unknown number of employees The company dec

A company has an unknown number of employees. The company decided to help employees to overcome their budgeting problem as follows: Each employee gets extra money based on the age of their dependants, if age of child is less than six, company pays $50 for each year of the child age, if age of child is less than ten. company pays $30 for each of the child age. otherwise company pays $20 for each child over ten. Design a program that prints each employee\'s name, number of child/children and at end of program print total extra money company paid lo the employees.

Solution

Follow the step:

package Chegg;
import java.util.List;
public class Employee {
   private String name;
   private int numOfChild = 0;
   private List<Integer> childAge = null;
   public String getName() {
       return name;
   }
   public void setName(String name) {
       this.name = name;
   }
   public int getNumOfChild() {
       return numOfChild;
   }
   public void setNumOfChild(int numOfChild) {
       this.numOfChild = numOfChild;
   }
   public List<Integer> getChildAge() {
       return childAge;
   }
   public void setChildAge(List<Integer> childAge) {
       this.childAge = childAge;
   }
}

package Chegg;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Company {
   public static void main(String[] args) {
       List<Employee> empList = new ArrayList<>();
       Employee emp = null;
       int choice = 0;
       Scanner scan = new Scanner(System.in);
       for (;;) {
           System.out.println(\"Enter 1. Add Employee 2. Print Detail 3.Exit\");
           choice = scan.nextInt();
           switch (choice) {
           case 1:
               List<Integer> childAge = new ArrayList<Integer>();
               emp = new Employee();
               System.out.println(\"Enter Employee Name:\");
               emp.setName(scan.next());
               System.out.println(\"Enter the number of child/childer\");
               emp.setNumOfChild(scan.nextInt());
               for (int i = 0; i < emp.getNumOfChild(); i++) {
                   System.out.println(\"Enter the age of \" + (i + 1) + \" child\");
                   childAge.add(scan.nextInt());
               }
               emp.setChildAge(childAge);
               empList.add(emp);
               break;
           case 2:
               printDetail(empList);
           default:
               break;
           }
       }
   }
   private static void printDetail(List<Employee> empList) {
       int totalMoney = 0;
       for (int i = 0; i < empList.size(); i++) {
           System.out.println(\"---------------------------------------------\");
           System.out.println(\"Name: \" + empList.get(i).getName());
           System.out.println(\"No of children: \" + empList.get(i).getNumOfChild());
           System.out.println(\"---------------------------------------------\");
           for (int j = 0; j < empList.get(i).getNumOfChild(); j++) {
               if (empList.get(i).getChildAge().get(j) < 6) {
                   totalMoney = totalMoney + (50 * empList.get(i).getChildAge().get(j));
               } else {
                   if (empList.get(i).getChildAge().get(j) < 10) {
                       totalMoney = totalMoney + (30 * empList.get(i).getChildAge().get(j));
                   } else {
                       totalMoney = totalMoney + (20 * empList.get(i).getChildAge().get(j));
                   }
               }
           }
       }
       System.out.println(\"Total extra money that company paid to employees are: $\" + totalMoney);
       System.out.println(\"____________________________________________________\");
   }
}

 A company has an unknown number of employees. The company decided to help employees to overcome their budgeting problem as follows: Each employee gets extra mo
 A company has an unknown number of employees. The company decided to help employees to overcome their budgeting problem as follows: Each employee gets extra mo

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site