Page 1 of 1

Need BonusTooLowException.java, MainThrow.java, and MainCatch.java Problem 1. Implement a class called BonusTooLowExcept

Posted: Mon May 02, 2022 11:38 am
by answerhappygod
Need BonusTooLowException.java, MainThrow.java, and
MainCatch.java
Problem 1. Implement a class called
BonusTooLowException, designed to be thrown when a
bonus value is less than $2000. Using the Executive class from
Chapter 10, create a main
program that creates and populates an Executive array with
information entered by the user
(array size as well). If a bonus value is entered that is too low,
i.e. less than $2000 throw the
exception. Allow the thrown exception to terminate the program.
Problem 2. Modify the solution to the program
above (submit a second file for this) such that it
catches and handles the exception if it is thrown. Handle the
exception by printing an
appropriate message and keeping the bonus=0, and then continue
entering more executive data.
Let the program conclude by printing the total number of executives
with valid bonuses, i.e.
positive, more than $2000, as well as the average pay.
Since Executive is a child of Employee, StaffMember, you can copy
the classes needed to your
homework folder.
Since exception handling process is different for each problem,
submit two separate driver
programs in addition to BonusTooLowException file.
abstract public class StaffMember {
protected String name;
protected String address;
protected String phone;
public StaffMember(String eName, String eAddress, String ePhone)
{
name = eName;
address = eAddress;
phone = ePhone;
}
public String toString() {
String result = "Name: " + name + "\n";
result += "Address: " + address + "\n";
result += "Phone: " + phone;
return result;
}
public abstract double pay();
}
public class Employee extends StaffMember
{
protected String socialSecurityNumber;
protected double payRate;
//
-----------------------------------------------------------------

// Constructor: Sets up this employee with the specified
// information.
//
-----------------------------------------------------------------

public Employee(String eName, String eAddress, String ePhone,
String
socSecNumber, double rate) {
super(eName, eAddress, ePhone);
socialSecurityNumber = socSecNumber;
payRate = rate;
}
public String toString() {
String result = super.toString();
result += "\nSocial Security Number: " +
socialSecurityNumber;
return result;
}
//
-----------------------------------------------------------------

// Returns the pay rate for this employee.
//
-----------------------------------------------------------------

public double pay() {
return payRate;
}
}
public class Executive extends Employee {
private double bonus;
//
-----------------------------------------------------------------

// Constructor: Sets up this executive with the specified
// information.
//
-----------------------------------------------------------------

public Executive(String eName, String eAddress, String ePhone,
String
socSecNumber, double rate) {
super(eName, eAddress, ePhone, socSecNumber, rate);
bonus = 0; // bonus has yet to be awarded
}
public void awardBonus(double execBonus) {
bonus = execBonus;
}
//
-----------------------------------------------------------------

// Computes and returns the pay for an executive, which is
the
// regular employee payment plus a one-time bonus.
//
-----------------------------------------------------------------

public double pay() {
double payment = super.pay() + bonus;
bonus = 0;
return payment;
}
}