Question

I need help in getting the second output to show both the commission rate and the...

I need help in getting the second output to show both the commission rate and the earnings for the String method output

package CompemsationTypes;

public class BasePlusCommissionEmployee extends CommissionEmployee

{

public void setGrossSales(double grossSales) {

super.setGrossSales(grossSales);

}

public double getGrossSales() {

return super.getGrossSales();

}

public void setCommissionRate(double commissionRate) {

super.setCommissionRate(commissionRate);

}

public double getCommissionRate() {

return super.getCommissionRate();

}

public String getFirstName() {

return super.getFirstName();

}

public String getLastName() {

return super.getLastName();

}

public String getSocialSecurityNumber() {

return super.getSocialSecurityNumber();

}

private double baseSalary;

public BasePlusCommissionEmployee(String firstName,String lastName,

String socialSecurityNumber,

double grossSales, double commissionRate,double baseSalary)

{

super(firstName, lastName, socialSecurityNumber,grossSales, commissionRate);

if (baseSalary < 0.0)

throw new IllegalArgumentException("Base salary must be >= 0.0");

this.baseSalary = baseSalary;

}

public void setBaseSalary(double baseSalary){

if (baseSalary < 0.0)

throw new IllegalArgumentException("Base salary must be >= 0.0");

this.baseSalary = baseSalary;

}

public double getBaseSalary(){

return baseSalary;

}

@Override

public double earnings(){

return getBaseSalary() + super.earnings();

}

@Override

public String toString(){

return String.format("%s %s%n%s: %.2f", "base-salaried",

super.toString(), "base salary", getBaseSalary());

}

}  

package CompemsationTypes;

public class BasePlusCommissionEmployeeTest{

public static void main(String[] args){

BasePlusCommissionEmployee employee = new BasePlusCommissionEmployee("John",

"Davis","615-818-7941", 1250, .07, 410);

System.out.println("Employee information gained using get methods:");

System.out.printf("%s %s%n", "First name is",employee.getFirstName());

System.out.printf("%s %s%n", "Last name is",employee.getLastName());

System.out.printf("%s %s%n", "Social security number is",

employee.getSocialSecurityNumber());

System.out.printf("%s %.2f%n", "Gross sales is",employee.getGrossSales());

System.out.printf("%s %.2f%n", "Commission rate is",employee.getCommissionRate());

System.out.printf("%s %.2f%n", "Base salary is",employee.getBaseSalary());

System.out.printf("%s %.2f%n", "Employee Earnings are",employee.earnings());

employee.setBaseSalary(1800);

employee.setCommissionRate(.1);

employee.earnings();

System.out.printf("%n%s:%n%n%s%n","Updated employee information, Dynamicly altered using the"

+ " toString Method",employee.toString());

}

}

package CompemsationTypes;

public class CommissionEmployee extends Employee{

private double grossSales;

private double commissionRate;

public CommissionEmployee(String firstName,String lastName,

String socialSecurityNumber,double grossSales,double commissionRate){

super(firstName, lastName, socialSecurityNumber);

if (grossSales < 0.0)

throw new IllegalArgumentException("Gross sales must be >= 0.0");

if (commissionRate <= 0.0 || commissionRate >= 1.0)

throw new IllegalArgumentException("Commission rate must be > 0.0 and "

+ "< 1.0");

this.grossSales = grossSales;

this.commissionRate = commissionRate;

}

public void setGrossSales(double grossSales){

if (grossSales < 0.0)

throw new IllegalArgumentException("Gross sales must be >= 0.0");

this.grossSales = grossSales;

}

public double getGrossSales(){

return grossSales;

}

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;

}

public double getCommissionRate(){

return commissionRate;

}

public double earnings(){

return grossSales * commissionRate;

}

public String toString(){

return super.toString()+String.format("%n%s: %.2f%n%s: %.2f","gross sales",

grossSales,"commission rate", commissionRate, "earnings",grossSales * commissionRate );

}

}

package CompemsationTypes;

public class CommissionEmployeeTest{

public static void main(String[] args){

CommissionEmployee employee = new CommissionEmployee("Vincent", "Carter",

"742-27-8544", 18000, .06);

System.out.println("Employee information gained using get methods:");

System.out.printf("%s %s%n", "First name is",employee.getFirstName());

System.out.printf("%s %s%n", "Last name is",employee.getLastName());

System.out.printf("%s %s%n", "Social security number is",

employee.getSocialSecurityNumber());

System.out.printf("%s %.2f%n", "Gross sales is",employee.getGrossSales());

System.out.printf("%s %.2f%n", "Commission rate is",employee.getCommissionRate());

employee.setGrossSales(13000);

employee.setCommissionRate(.4);

System.out.printf("%n%s:%n%n%s%n","Updated employee information, Dynamicly altered using the"

+ " toString Method", employee);

}

}

package CompemsationTypes;

public class Employee{

private final String firstName;

private final String lastName;

private final String socialSecurityNumber;

public Employee(String firstName,String lastName, String socialSecurityNumber){

this.firstName = firstName;

this.lastName = lastName;

this.socialSecurityNumber = socialSecurityNumber;

}

public String getFirstName(){

return firstName;

}

public String getLastName(){

return lastName;

}

public String getSocialSecurityNumber(){

return socialSecurityNumber;

}

@Override

public String toString(){

return String.format("%s: %s %s%n%s: %s","commission employee", firstName,

lastName,"social security number", socialSecurityNumber);

}

}

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

If you have any doubts, please give me comment...

public class CommissionEmployee extends Employee {

private double grossSales;

private double commissionRate;

public CommissionEmployee(String firstName, String lastName, String socialSecurityNumber, double grossSales,

double commissionRate) {

super(firstName, lastName, socialSecurityNumber);

if (grossSales < 0.0)

throw new IllegalArgumentException("Gross sales must be >= 0.0");

if (commissionRate <= 0.0 || commissionRate >= 1.0)

throw new IllegalArgumentException("Commission rate must be > 0.0 and " + "< 1.0");

this.grossSales = grossSales;

this.commissionRate = commissionRate;

}

public void setGrossSales(double grossSales) {

if (grossSales < 0.0)

throw new IllegalArgumentException("Gross sales must be >= 0.0");

this.grossSales = grossSales;

}

public double getGrossSales() {

return grossSales;

}

[anunaga@anunaga 15052018]$ javac CommissionEmployeeTest.java [anunagaanunaga 15052018]$ java CommissionEmployeeTest Employee

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;

}

public double getCommissionRate() {

return commissionRate;

}

public double earnings() {

return grossSales * commissionRate;

}

public String toString() {

return super.toString() + String.format("\n%s: %.2f\n%s: %.2f\n%s: %.2f\n", "gross sales", grossSales, "commission rate", commissionRate, "earnings", grossSales * commissionRate);

}

}

Add a comment
Know the answer?
Add Answer to:
I need help in getting the second output to show both the commission rate and the...
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
  • Add an HourlyPlusCommissionEmployee class to the PayrollSystem app by subclassing an existing class. A HourlyPlusCommissionEmployee is...

    Add an HourlyPlusCommissionEmployee class to the PayrollSystem app by subclassing an existing class. A HourlyPlusCommissionEmployee is a kind of CommissionEmployee with the following differences and specifications: HourlyPlusCommissionEmployee earns money based on 2 separate calculations: commissions are calculated by the CommissionEmployee base class hourly pay is calculated exactly the same as the HourlyEmployee class, but this is not inherited, it must be duplicated in the added class BasePlusCommissionEmployee inherits from CommissionEmployee and includes (duplicates) the details of SalariedEmployee. Use this as...

  • HOW TO FiX EXCEPTIONS??? In order to populate the array, you will need to split() each...

    HOW TO FiX EXCEPTIONS??? In order to populate the array, you will need to split() each String on the (,) character so you can access each individual value of data. Based on the first value (e.g., #) your method will know whether to create a new Manager, HourlyWorker, or CommissionWorker object. Once created, populate the object with the remaining values then store it in the array. Finally, iterate through the array of employees using the enhanced for loop syntax, and...

  • By editing the code below to include composition, enums, toString; must do the following: Prompt the...

    By editing the code below to include composition, enums, toString; must do the following: Prompt the user to enter their birth date and hire date (see Fig. 8.7, 8.8 and 8.9 examples) in addition to the previous user input Create a new class that validates the dates that are input (can copy date class from the book) Incorporate composition into your class with these dates Use enums to identify the employee status as fulltime (40 or more hours worked for...

  • NETBEANS JAVA BANK PROGRAM (TAKE SCREENSHOTS FROM NETBEANS INCLUDING OUTPUT PLEASE) Display the accounts for the...

    NETBEANS JAVA BANK PROGRAM (TAKE SCREENSHOTS FROM NETBEANS INCLUDING OUTPUT PLEASE) Display the accounts for the current displayed customer PLEASEEEEEEEEEE package bankexample; import java.util.UUID; public class Customer { private UUID id; private String email; private String password; private String firstName; private String lastName;    public Customer(String firstName, String lastName, String email, String password) { this.id = UUID.randomUUID(); this.firstName = firstName; this.lastName = lastName; this.email = email; this.password = password; } public String getFirstName() { return firstName; } public void setFirstName(String...

  • In the processLineOfData, write the code to handle case "H" of the switch statement such that:...

    In the processLineOfData, write the code to handle case "H" of the switch statement such that: An HourlyEmployee object is created using the firstName, lastName, rate, and hours local variables. Notice that rate and hours need to be converted from String to double. You may use parseDouble method of the Double class as follows:               Double.parseDouble(rate) Call the parsePaychecks method in this class passing the HourlyEmployee object created in the previous step and the checks variable. Call the findDepartment method...

  • In the processLineOfData method, write the code to handle case "H" of the switch statement such...

    In the processLineOfData method, write the code to handle case "H" of the switch statement such that: • An HourlyEmployee object is created using the firstName, lastName, rate, and hours local variables. Notice that rate and hours need to be converted from String to double. You may use parseDouble method of the Double class as follows: Double.parseDouble(rate) Call the parsePaychecks method in this class passing the Hourly Employee object created in the previous step and the checks variable. Call the...

  • What is wrong with this Code? Fix the code errors to run correctly without error. There...

    What is wrong with this Code? Fix the code errors to run correctly without error. There are two parts for one code (one question) the two parts branch off, one part has 2 sheets of code, the other has 3 sheets of code, all are small code segments for one question. Pt.1 - 2 sheets of code: public class Computer { private String make; private String type; private String modelNumber; private double cpuSpeed_GHz; private int ramSize_GB; private int hardDriveSize_GB; private...

  • I have a little problem about my code. when i'm working on "toString method" in "Course"...

    I have a little problem about my code. when i'm working on "toString method" in "Course" class, it always say there is a mistake, but i can not fix it: Student class: public class Student {    private String firstName;    private String lastName;    private String id;    private boolean tuitionPaid;       public Student(String firstName, String lastName, String id, boolean tuitionPaid)    {        this.firstName=firstName;        this.lastName=lastName;        this.id=id;        this.tuitionPaid=tuitionPaid;    }   ...

  • Cant figure out how to fix error Code- import java.io.File; import java.io.IOException; import java.util.*; public class Program8 {    public static void main(String[] args)throws IOException{       ...

    Cant figure out how to fix error Code- import java.io.File; import java.io.IOException; import java.util.*; public class Program8 {    public static void main(String[] args)throws IOException{        File prg8 = new File("program8.txt");        Scanner reader = new Scanner(prg8);        String cName = "";        int cID = 0;        double bill = 0.0;        String email = "";        double nExempt = 0.0;        String tExempt = "";        int x = 0;        int j = 1;        while(reader.hasNextInt()) {            x = reader.nextInt();}        Customers c1 [] = new Customers [x];        for (int...

  • What is the problem with my Program ? also I need a Jframe that desplays the...

    What is the problem with my Program ? also I need a Jframe that desplays the original input on the left side and the sorted input of the left side. my program is supose to read the number for basketball players, first name, last name, and float number that is less than 0 . on the left sideit is supposed to sort all this input based on last name. This is my demo class : package baseball; import java.io.*; import...

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