Question

4. Create a Business class. This class should store an array of Employee objects. Add a...

4. Create a Business class. This class should store an array of Employee objects. Add a method to add employees to the Business, similar to addFoodItem in the Meal class. Add two more methods for the Business class: getHighestPaid(), which returns the Employee who has been paid the most in total, and getHighestTaxed(), which returns the Employee who has been taxed the most in total. Note: you do not need to handle the case of ties.

These are all the given and needed classes.

public class Employee extends Person {
    double weeklyBaseSalary;
    double totalPaid;
    double totalTaxed;

    public Employee(String iName, int iAge, double baseSal) {
        super(iName, iAge);
        this.weeklyBaseSalary = baseSal;
    }

    /*
     * Should update the total amount paid/taxed for this employee.
     * Taxes should be 10% of the weekly base salary for employees under the age of 30
     * and 15% for employees aged 30 or older.
     * The total paid to the employee should be the amount remaining after taxes are paid
     */
    public void pay() {
        if (getAge() < 30) {
            totalTaxed = 0.10 * weeklyBaseSalary;
        } else {
            totalTaxed = 0.15 * weeklyBaseSalary;
        }
        totalPaid = weeklyBaseSalary - totalTaxed;
    }

    /*
     * Should return a String representing the employee’s pay cheque.
     * The pay cheque must contain the following information: the employee’s name and age,
     * the weekly base salary, the amount paid in taxes, the amount paid to the employee.
     */
    public String makePaycheque() {
        String result = "";
        result += "Name: " + getName() + ", Age: " + getAge() + "\n";
        result += "Weekly base salary: " + weeklyBaseSalary + "\n";
        result += "Amount paid in taxes: " + totalTaxed;
        result += "Amount paid to the employee: " + totalPaid;
        return result;
    }
    //Add any additional methods you require here
}

public class Person{
private String name;
private int age;

public Person(String iName, int iAge){
name = iName;
age = iAge;
}

public String getName(){
return name;
}

public int getAge(){
return age;
}
}

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

/*Java program to test the Business class. The below java program create an instance of Business class
* and then add Employee objects Then find the max paid employee and the max tax paid employee.*/
//TestBusiness.java

public class TestBusiness
{
   public static void main(String[] args)
   {
       //create a Business class object
       Business realestatebiz=new Business();
       //Add Employee objects to the Business class
       realestatebiz.add(new Employee("johnson", 35, 25000));
       realestatebiz.add(new Employee("mark", 33, 30000));
       realestatebiz.add(new Employee("sameer", 28, 35000));
       realestatebiz.add(new Employee("milan", 30, 45000));
      
       //print the paycheque to console
       for (int i = 0; i < realestatebiz.getsize(); i++)
       {
           System.out.println(realestatebiz.getEmployee(i).makePaycheque());
       }
      
       //print highest paid amount
       System.out.printf("Max paid employee : $%.2f\n",realestatebiz.getHighestPaid().getPay());
       //print highest tax amount
       System.out.printf("Max tax paid employee : $%.2f\n",realestatebiz.getHighestTaxed().getTaxPaid());
   }
}
---------------------------------------------------------------------------

//Business.java
import java.util.ArrayList;
public class Business
{
   //an array list of Employee class
   private ArrayList<Employee>emps;
   public Business()
   {
       //create an instanace of ArrayList of EMployee type
       emps=new ArrayList<Employee>();
   }
   /*Method,add that takes Employee object
   * as argument and add the employee object
   * to the array list, emps*/
   public void add(Employee emp)
   {
       emps.add(emp);
   }
   public int getsize()
   {
       return emps.size();
   }
   public Employee getEmployee(int index)
   {
       return emps.get(index);
   }
   /*The method, getHighestPaid that returns the highest
   * paid employee*/
   public Employee getHighestPaid()
   {
       Employee maxpaid=emps.get(0);
       for (int i = 0; i < emps.size(); i++)
       {
           if(emps.get(i).getPay()>maxpaid.getPay())
           {
               maxpaid=emps.get(i);
           }          
       }
       //return maxpaid
       return maxpaid;
   }
   /*The method, getHighestTaxed that returns the highest
   * tax paid employee*/
   public Employee getHighestTaxed()
   {
       Employee maxtax=emps.get(0);
       for (int i = 0; i < emps.size(); i++)
       {
           if(emps.get(i).getTaxPaid()>maxtax.getTaxPaid())
           {
               maxtax=emps.get(i);
           }          
       }
       //return maxtax
       return maxtax;
   }
} //end of the Business class
---------------------------------------------------------------------------

//Employee.java
public class Employee extends Person
{
   double weeklyBaseSalary;
   double totalPaid;
   double totalTaxed;

   public Employee(String iName, int iAge, double baseSal) {
       super(iName, iAge);
       this.weeklyBaseSalary = baseSal;
       pay();
   }
   public double getPay()
   {
       return totalPaid;
   }

   public double getTaxPaid()
   {
       return totalTaxed;
   }

   /*
   * Should update the total amount paid/taxed for this employee.
   * Taxes should be 10% of the weekly base salary for employees under the age of 30
   * and 15% for employees aged 30 or older.
   * The total paid to the employee should be the amount remaining after taxes are paid
   */
   public void pay() {
       if (getAge() < 30) {
           totalTaxed = 0.10 * weeklyBaseSalary;
       } else {
           totalTaxed = 0.15 * weeklyBaseSalary;
       }
       totalPaid = weeklyBaseSalary - totalTaxed;
   }

   /*
   * Should return a String representing the employee’s pay cheque.
   * The pay cheque must contain the following information: the employee’s name and age,
   * the weekly base salary, the amount paid in taxes, the amount paid to the employee.
   */
   public String makePaycheque() {
       String result = "";
       result += "Name: " + getName() + ", Age: " + getAge() + "\n";
       result += "Weekly base salary: " + weeklyBaseSalary + "\n";
       result += "Amount paid in taxes: " + totalTaxed;
       result += "Amount paid to the employee: " + totalPaid+"\n";
       return result;
   }
   //Add any additional methods you require here
}

---------------------------------------------------------------------------

//Person.java
public class Person{
   private String name;
   private int age;
   public Person(String iName, int iAge){
       name = iName;
       age = iAge;
   }
   public String getName(){
       return name;
   }
   public int getAge(){
       return age;
   }
}

---------------------------------------------------------------------------

Sample Output:

Name: johnson, Age: 35
Weekly base salary: 25000.0
Amount paid in taxes: 3750.0Amount paid to the employee: 21250.0

Name: mark, Age: 33
Weekly base salary: 30000.0
Amount paid in taxes: 4500.0Amount paid to the employee: 25500.0

Name: sameer, Age: 28
Weekly base salary: 35000.0
Amount paid in taxes: 3500.0Amount paid to the employee: 31500.0

Name: milan, Age: 30
Weekly base salary: 45000.0
Amount paid in taxes: 6750.0Amount paid to the employee: 38250.0

Max paid employee : $38250.00
Max tax paid employee : $6750.00

Add a comment
Know the answer?
Add Answer to:
4. Create a Business class. This class should store an array of Employee objects. Add a...
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
  • In Java: Executable Class create an array of Employee objects. You can copy the array you...

    In Java: Executable Class create an array of Employee objects. You can copy the array you made for Chapter 20. create an ArrayList of Employee objects from that array. use an enhanced for loop to print all employees as shown in the sample output. create a TreeMap that uses Strings for keys and Employees as values. this TreeMap should map Employee ID numbers to their associated Employees. process the ArrayList to add elements to this map. print all employees in...

  • Using your Dog class from earlier this week, complete the following: Create a new class called...

    Using your Dog class from earlier this week, complete the following: Create a new class called DogKennel with the following: Instance field(s) - array of Dogs + any others you may want Contructor - default (no parameters) - will make a DogKennel with no dogs in it Methods: public void addDog(Dog d) - which adds a dog to the array public int currentNumDogs() - returns number of dogs currently in kennel public double averageAge() - which returns the average age...

  • Money Lab using arraylists in Java Using the Coin class below create a program with the...

    Money Lab using arraylists in Java Using the Coin class below create a program with the following requirements Create an arraylist that holds the money you have in your wallet. You will add a variety of coins(coin class) and bills (ones, fives, tens *also using the coin class) to your wallet arraylist. Program must include a loop that asks you to purchase items using the coins in your wallet. When purchasing items, the program will remove coins from the arraylist...

  • In the Employee class, add an implementation for the calculatePension() method declared in the interface. Calculate...

    In the Employee class, add an implementation for the calculatePension() method declared in the interface. Calculate the pension to date as the equivalent of a monthly salary for every year in service. 4) Print the calculated pension for all employees. ************** I added the interface and I implemented the interface with Employee class but, I don't know how can i call the method in main class ************ import java.io.*; public class ManagerTest { public static void main(String[] args) { InputStreamReader...

  • 1. Write a new class, Cat, derived from PetRecord – Add an additional attribute to store...

    1. Write a new class, Cat, derived from PetRecord – Add an additional attribute to store the number of lives remaining: numLives – Write a constructor that initializes numLives to 9 and initializes name, age, & weight based on formal parameter values 2. Write a main method to test your Cat constructor & call the inherited writeOutput() method 3. Write a new writeOutput method in Cat that uses “super” to print the Cat’s name, age, weight & numLives – Does...

  • c++ only Design a class representing an Employee. The employee would have at least these private...

    c++ only Design a class representing an Employee. The employee would have at least these private fields (Variables): name: string (char array) ID: string (char array) salary: float Type: string (char array) All the variables except for the salary should have their respective setters and getters, and the class should have two constructors, one is the default constructor and the other constructor initializes the name,ID and type of employee with valid user input. The class should have the following additional...

  • I need help with this one method in java. Here are the guidelines. Only public Employee[]...

    I need help with this one method in java. Here are the guidelines. Only public Employee[] findAllBySubstring(String find). EmployeeManager EmployeeManager - employees : Employee[] - employeeMax : final int = 10 -currentEmployees : int <<constructor>> EmployeeManager + addEmployee( type : int, fn : String, ln : String, m : char, g : char, en : int, ft : boolean, amount : double) + removeEmployee( index : int) + listAll() + listHourly() + listSalary() + listCommision() + resetWeek() + calculatePayout() :...

  • 2. Given following Java program, convert to class diagram, create two instances of Employee, and initialize...

    2. Given following Java program, convert to class diagram, create two instances of Employee, and initialize them with following values: For employee1, name – your friend’s name, salary = 30000, 8 hours and avail is false For employee2, name – your friend’s name, salary = 80000, 10 hours and avail is true public class Employee { private String name; private double salary ; private int hours ; private boolean avail ; public Employee (double r, double h, boolean hd) {...

  • C# Hey I am having trouble implementing additonal function to this assignment: Problem: Implement three IComparer classes on Employee - NameComparer, AgeComparer, and PayComparer - that allow Employee...

    C# Hey I am having trouble implementing additonal function to this assignment: Problem: Implement three IComparer classes on Employee - NameComparer, AgeComparer, and PayComparer - that allow Employees to be compared by the Name, Age, and Pay, respectively. Code: Employee.Core.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Employees { partial class Employee { // Field data. private string empName; private int empID; private float currPay; private int empAge; private string empSSN = ""; private string empBene...

  • I have written my code for an employee management system that stores Employee class objects into...

    I have written my code for an employee management system that stores Employee class objects into a vector, I am getting no errors until I try and compile, I am getting the error: C2679 binary '==': no operator found which takes a right-hand operand of type 'const std::string' (or there is no acceptable conversion). But I am not sure why any help would be great, Thank you! 1 2 3 4 5 6 7 8 9 10 11 12 13...

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