Question
I need some help with this solution, as we have a very specific way to approach it. I need to throw an Exception rather than
I need some help with this solution, as we have a very specific way to approach it. I need to throw an Exception rather than reset it to zero as previously thought, but I'm completely stuck on that. Can I get some help with this JAVA code, specifically with the bolded part regarding the validation of baseSalary being > 0?
public class BasePlusCommissionEmployeeComposition {
private CommissionEmployee commissionEmployee;
private double baseSalary;
// Declare the constructor BasePlusCommissionEmployee
public BasePlusCommissionEmployeeComposition( String first, String last,
String ssn, double sales, double rate, double salary )
{
commissionEmployee = new CommissionEmployee( first, last, ssn, sales, rate );
// Store the salary
setBaseSalary( salary );
}
// Accessor setFirstName()
public void setFirstName( String first )
{
commissionEmployee.setFirstName( first );
}
// Mutator FirstName
public String getFirstName()
{
return commissionEmployee.getFirstName();
}
// Accessor LastName()
public void setLastName( String last )
{
commissionEmployee.setLastName( last );
}
// Mutator LastName()
public String getLastName()
{
return commissionEmployee.getLastName();
}
// Accessor SocialSecurityNumber()
public void setSocialSecurityNumber( String ssn )
{
commissionEmployee.setSocialSecurityNumber( ssn );
}
// Mutator SocialSecurityNumber()
public String getSocialSecurityNumber()
{
return commissionEmployee.getSocialSecurityNumber();
}
// Accessor GrossSales()
public void setGrossSales( double sales )
{
commissionEmployee.setGrossSales( sales );
}
// Mutator GrossSales()
public double getGrossSales()
{
return commissionEmployee.getGrossSales();
}
// Accessor CommissionRate()
public void setCommissionRate( double rate )
{
commissionEmployee.setCommissionRate( rate );
}
// Mutator CommissionRate()
public double getCommissionRate()
{
return commissionEmployee.getCommissionRate();
}
// Accessor BaseSalary()
public void setBaseSalary( double salary )
{
baseSalary = ( salary < 0.0 ) ? 0.0 : salary;
}
// Mutator BaseSalary()
public double getBaseSalary()
{
return baseSalary;
}
// Mutator BaseSalary()
public double earnings()
{
return getBaseSalary() + commissionEmployee.earnings();
}
@Override
public String toString()
{
return String.format( "%s %s %s: %.2f", "base-salaried",
commissionEmployee.toString(), "base salary", getBaseSalary() );
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started