I want the class, BasePlusCommissionEmployee, to contain a reference to a CommisionEmployee object. Instead of the inheritance. *Code in Question below* public class CommissionEmployee { private final String firstName; private final String lastName; private final String socialSecurityNumber; private double grossSales; // gross weekly sales private double commissionRate; // commission percentage // five-argument constructor public CommissionEmployee(String firstName, String lastName, String socialSecurityNumber, double grossSales, double commissionRate) { // implicit call to Object constructor occurs here // if grossSales is invalid throw exception if (grossSales < 0.0) { throw new IllegalArgumentException("Gross sales must be >= 0.0"); } // if commissionRate is invalid throw exception if (commissionRate <= 0.0 || commissionRate >= 1.0) { throw new IllegalArgumentException( "Commission rate must be > 0.0 and < 1.0"); } this.firstName = firstName; this.lastName = lastName; this.socialSecurityNumber = socialSecurityNumber; this.grossSales = grossSales; this.commissionRate = commissionRate; } // return first name public String getFirstName() {return firstName;} // return last name public String getLastName() {return lastName;} // return social security number public String getSocialSecurityNumber() {return socialSecurityNumber;} // set gross sales amount public void setGrossSales(double grossSales) { if (grossSales < 0.0) { throw new IllegalArgumentException("Gross sales must be >= 0.0"); } this.grossSales = grossSales; } // return gross sales amount public double getGrossSales() {return grossSales;} // set commission rate public void setCommissionRate(double commissionRate) { if (commissionRate <= 0.0 || commissionRate >= 1.0) { throw new IllegalArgumentException( "Commission rate must be > 0.0 and < 1.0"); } this.commissionRate = commissionRate; } // return commission rate public double getCommissionRate() {return commissionRate;} // calculate earnings public double earnings() { return getCommissionRate() * getGrossSales(); } // return String representation of CommissionEmployee object @Override public String toString() { return String.format("%s: %s %s%n%s: %s%n%s: %.2f%n%s: %.2f", "commission employee", getFirstName(),getLastName(), "social security number", getSocialSecurityNumber(), "gross sales",getGrossSales() , "commission rate", getCommissionRate() ); } } -------------------------------------------------------------------------------------------------------------------------------------------------- public class BasePlusCommissionEmployee extends CommissionEmployee { private double baseSalary; // base salary per week // six-argument constructor public BasePlusCommissionEmployee(String firstName, String lastName, String socialSecurityNumber, double grossSales, double commissionRate, double baseSalary) { super(firstName, lastName, socialSecurityNumber, grossSales, commissionRate); // if baseSalary is invalid throw exception if (baseSalary < 0.0) { throw new IllegalArgumentException("Base salary must be >= 0.0"); } this.baseSalary = baseSalary; } // set base salary public void setBaseSalary(double baseSalary) { if (baseSalary < 0.0) { throw new IllegalArgumentException("Base salary must be >= 0.0"); } this.baseSalary = baseSalary; } // return base salary public double getBaseSalary() {return baseSalary;} // calculate earnings @Override public double earnings() { } // return String representation of BasePlusCommissionEmployee40 @Override public String toString() { } }
I want the class, BasePlusCommissionEmployee, to contain a reference to a CommisionEmployee object. Instead of the inheritance. *Code in Question below* public class CommissionEmployee { private final String firstName; private final String lastName; private final String socialSecurityNumber; private double grossSales; // gross weekly sales private double commissionRate; // commission percentage // five-argument constructor public CommissionEmployee(String firstName, String lastName, String socialSecurityNumber, double grossSales, double commissionRate) { // implicit call to Object constructor occurs here // if grossSales is invalid throw exception if (grossSales < 0.0) { throw new IllegalArgumentException("Gross sales must be >= 0.0"); } // if commissionRate is invalid throw exception if (commissionRate <= 0.0 || commissionRate >= 1.0) { throw new IllegalArgumentException( "Commission rate must be > 0.0 and < 1.0"); } this.firstName = firstName; this.lastName = lastName; this.socialSecurityNumber = socialSecurityNumber; this.grossSales = grossSales; this.commissionRate = commissionRate; } // return first name public String getFirstName() {return firstName;} // return last name public String getLastName() {return lastName;} // return social security number public String getSocialSecurityNumber() {return socialSecurityNumber;} // set gross sales amount public void setGrossSales(double grossSales) { if (grossSales < 0.0) { throw new IllegalArgumentException("Gross sales must be >= 0.0"); } this.grossSales = grossSales; } // return gross sales amount public double getGrossSales() {return grossSales;} // set commission rate public void setCommissionRate(double commissionRate) { if (commissionRate <= 0.0 || commissionRate >= 1.0) { throw new IllegalArgumentException( "Commission rate must be > 0.0 and < 1.0"); } this.commissionRate = commissionRate; } // return commission rate public double getCommissionRate() {return commissionRate;} // calculate earnings public double earnings() { return getCommissionRate() * getGrossSales(); } // return String representation of CommissionEmployee object @Override public String toString() { return String.format("%s: %s %s%n%s: %s%n%s: %.2f%n%s: %.2f", "commission employee", getFirstName(),getLastName(), "social security number", getSocialSecurityNumber(), "gross sales",getGrossSales() , "commission rate", getCommissionRate() ); } } -------------------------------------------------------------------------------------------------------------------------------------------------- public class BasePlusCommissionEmployee extends CommissionEmployee { private double baseSalary; // base salary per week // six-argument constructor public BasePlusCommissionEmployee(String firstName, String lastName, String socialSecurityNumber, double grossSales, double commissionRate, double baseSalary) { super(firstName, lastName, socialSecurityNumber, grossSales, commissionRate); // if baseSalary is invalid throw exception if (baseSalary < 0.0) { throw new IllegalArgumentException("Base salary must be >= 0.0"); } this.baseSalary = baseSalary; } // set base salary public void setBaseSalary(double baseSalary) { if (baseSalary < 0.0) { throw new IllegalArgumentException("Base salary must be >= 0.0"); } this.baseSalary = baseSalary; } // return base salary public double getBaseSalary() {return baseSalary;} // calculate earnings @Override public double earnings() { } // return String representation of BasePlusCommissionEmployee40 @Override public String toString() { } }
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
I want the class, BasePlusCommissionEmployee, to contain a reference to a CommisionEmployee object. Instead of the inheritance.
*Code in Question below*
public class CommissionEmployee {
private final String firstName;
private final String lastName;
private final String socialSecurityNumber;
private double grossSales; // gross weekly sales
private double commissionRate; // commission percentage
// five-argument constructor
public CommissionEmployee(String firstName, String lastName,
String socialSecurityNumber, double grossSales,
double commissionRate) {
// implicit call to Object constructor occurs here
// if grossSales is invalid throw exception
if (grossSales < 0.0) {
throw new IllegalArgumentException("Gross sales must be >= 0.0");
}
// if commissionRate is invalid throw exception
if (commissionRate <= 0.0 || commissionRate >= 1.0) {
throw new IllegalArgumentException(
"Commission rate must be > 0.0 and < 1.0");
}
this.firstName = firstName;
this.lastName = lastName;
this.socialSecurityNumber = socialSecurityNumber;
this.grossSales = grossSales;
this.commissionRate = commissionRate;
}
// return first name
public String getFirstName() {return firstName;}
// return last name
public String getLastName() {return lastName;}
// return social security number
public String getSocialSecurityNumber() {return socialSecurityNumber;}
// set gross sales amount
public void setGrossSales(double grossSales) {
if (grossSales < 0.0) {
throw new IllegalArgumentException("Gross sales must be >= 0.0");
}
this.grossSales = grossSales;
}
// return gross sales amount
public double getGrossSales() {return grossSales;}
// set commission rate
public void setCommissionRate(double commissionRate) {
if (commissionRate <= 0.0 || commissionRate >= 1.0) {
throw new IllegalArgumentException(
"Commission rate must be > 0.0 and < 1.0");
}
this.commissionRate = commissionRate;
}
// return commission rate
public double getCommissionRate() {return commissionRate;}
// calculate earnings
public double earnings()
{ return getCommissionRate() * getGrossSales(); }
// return String representation of CommissionEmployee object
@Override
public String toString() {
return String.format("%s: %s %s%n%s: %s%n%s: %.2f%n%s: %.2f",
"commission employee", getFirstName(),getLastName(),
"social security number", getSocialSecurityNumber(),
"gross sales",getGrossSales() ,
"commission rate", getCommissionRate() );
}
}
--------------------------------------------------------------------------------------------------------------------------------------------------
public class BasePlusCommissionEmployee extends CommissionEmployee {
private double baseSalary; // base salary per week
// six-argument constructor
public BasePlusCommissionEmployee(String firstName, String lastName,
String socialSecurityNumber, double grossSales,
double commissionRate, double baseSalary) {
super(firstName, lastName, socialSecurityNumber,
grossSales, commissionRate);
// if baseSalary is invalid throw exception
if (baseSalary < 0.0) { throw new IllegalArgumentException("Base salary must be >= 0.0");
}
this.baseSalary = baseSalary;
}
// set base salary
public void setBaseSalary(double baseSalary) {
if (baseSalary < 0.0) {
throw new IllegalArgumentException("Base salary must be >= 0.0");
}
this.baseSalary = baseSalary;
}
// return base salary
public double getBaseSalary() {return baseSalary;}
// calculate earnings
@Override
public double earnings() { }
// return String representation of BasePlusCommissionEmployee40 @Override
public String toString() {
}
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps with 2 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education