Many programs written with inheritance could be written with composition instead, and vice versa. Rewrite class BasePlus-CommissionEmployee
Question:
Many programs written with inheritance could be written with composition instead, and vice versa. Rewrite class BasePlus-CommissionEmployee (Fig. 9.11) of the CommissionEmployee–BasePlusCommissionEmployee hierarchy so that it contains a reference to a CommissionEmployee object, rather than inheriting from class CommissionEmployee. Retest BasePlusCommissionEmployee to demonstrate that it still provides the same functionality.
Fig. 9.11
Transcribed Image Text:
1 2 3 4 10 II 12 5 public class BasePlusCommission Employee extends Commission Employee { private double baseSalary; // base salary per week 6 7 8 13 14 15 16 17 18 Imm 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 44 42 45 44 45 41 // Fig. 9.11: BasePlusCommission Employee.java // BasePlusCommission Employee class inherits from Commission Employee // and accesses the superclass's private data via inherited // public methods. 43 } // six-argument constructor public BasePlusCommission Employee (String firstName, String lastName, String social SecurityNumber, double grossSales, double commission Rate, double baseSalary) { super(firstName, lastName, social SecurityNumber, grossSales, commissionRate); // if baseSalary is invalid throw exception if (baseSalary < 0.0) { throw new Illegal ArgumentException ("Base salary must be >= 0.0"); } this.baseSalary = baseSalary; } // set base salary public void setBase Salary(double baseSalary) { if (baseSalary < 0.0) { throw new IllegalArgumentException ("Base salary must be >= 0.0"); } this.baseSalary = baseSalary; } // return base salary public double getBase Salary() {return baseSalary;} // calculate earnings @Override public double earnings() {return getBaseSalary() + super. earnings (); } } // return String representation of BasePlusCommission Employee @Override public String toString() { return String.format("%s %s %n%s: %.2f", "base-salaried", super.toString(), "base salary", getBaseSalary());
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 0% (1 review)
The provided code shows a BasePlusCommissionEmployee class ...View the full answer
Answered By
Aysha Ali
my name is ayesha ali. i have done my matriculation in science topics with a+ . then i got admission in the field of computer science and technology in punjab college, lahore. i have passed my final examination of college with a+ also. after that, i got admission in the biggest university of pakistan which is university of the punjab. i am studying business and information technology in my university. i always stand first in my class. i am very brilliant client. my experts always appreciate my work. my projects are very popular in my university because i always complete my work with extreme devotion. i have a great knowledge about all major science topics. science topics always remain my favorite topics. i am also a home expert. i teach many clients at my home ranging from pre-school level to university level. my clients always show excellent result. i am expert in writing essays, reports, speeches, researches and all type of projects. i also have a vast knowledge about business, marketing, cost accounting and finance. i am also expert in making presentations on powerpoint and microsoft word. if you need any sort of help in any topic, please dont hesitate to consult with me. i will provide you the best work at a very reasonable price. i am quality oriented and i have 5 year experience in the following field.
matriculation in science topics; inter in computer science; bachelors in business and information technology
_embed src=http://www.clocklink.com/clocks/0018-orange.swf?timezone=usa_albany& width=200 height=200 wmode=transparent type=application/x-shockwave-flash_
4.40+
11+ Reviews
14+ Question Solved
Related Book For
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates
Question Posted:
Students also viewed these Computer science questions
-
Many programs written with inheritance could be written with composition instead, and vice versa. Rewrite class Base Plus Commission Employee (Fig. 9.11) of the Commission Employee-Base Plus...
-
Visual C# (Made in a Console App) 11.3 (Composition vs. Inheritance) Many apps written with inheritance could be written with composition instead, and vice cersa. Rewrite class...
-
Case Study: Quick Fix Dental Practice Technology requirements Application must be built using Visual Studio 2019 or Visual Studio 2017, professional or enterprise. The community edition is not...
-
A table of properties for methyl chloride lists the saturation pressure as 116.7 psia at 100oF. At 100oF, this table also lists hfg = 154.85 Btu/lbm, and vfg = 0.86332 ft3/lbm. Estimate the...
-
Consider a compressible, laminar boundary layer over a flat plate. Assuming Pr = 1 and a calorically perfect gas, show that the profile of total temperature through the boundary layer is a function...
-
The balance sheets of Percy Corp. and Saltz Ltd. on December 31, Year 10, are shown below: The fair values of the identifiable net assets of Saltz Ltd. on December 31, Year 10, In addition to the...
-
Ticker Services began operations in 2011 and maintains long-term investments in available-for-sale securi ties. The year-end cost and fair values for its portfolio of these investments follow....
-
The following data pertains to the operations of Knight Corporation for 2012: The controller is trying to decide which method of accounting for bad debts to use. The company is attempting to maximize...
-
South Fertilizers Limited begins operations with $10,000 cash on 1 st January, 2020. With the available cash, the company immediately purchased 1000 bags (50 kg per bag) of fertilizer at the price of...
-
Every additional line of code is an opportunity for a defect. Discuss the ways in which inheritance promotes defect reduction.
-
In a global economy, dealing with currencies, monetary amounts, conversions, rounding and formatting is complex. The new JavaMoney API was developed to meet these challenges. At the time of this...
-
A regression model to predict the price of diamonds included the following predictor variables: the weight of the stone (in carats where 1 carat = 0.2 gram), the color rating (D, E, F, G, H, or I),...
-
X Calculate the reaction rate at various conversions, as shown below: FAO -TA -TA 0.2 0.8 Considering that for a PFR: dx V = FAO What is the conversion reached after the 50 m of this PFR?
-
For decades, leaders have talked about flexible working options, yet only few companies were consistently using these practices prior to the global health crisis of 2020. In March 2020, organizations...
-
Manatee Corp. has developed standard costs based on a predicted operating level of 352,000 units of production, which is 80% of capacity. Variable overhead is $281,600 at this level of activity, or...
-
When leaders are facing a crisis or an opportunity, generally, they tend to fall back on the leadership style that has worked for them in the past. Discuss with examples the options that would help...
-
Data Table the pasteet dollar -X Total sales revenues 2 Number of units produced and sold 500,000 units Selling price nt. $ 230,000 te Operating Income Total Investment in assets Variable cost per...
-
A graph of a function is shown. Using the graph, find the indicated function values; that is, given the inputs, find the outputs. (a) h(1), h(3), and h(4) (b) t(- 4), t(0), and t(3) (c) s(- 4), s(-...
-
The value of a share of common stock depends on the cash flows it is expected to provide, and those flows consist of the dividends the investor receives each year while holding the stock and the...
-
Consider the data center network with hierarchical topology in Figure 6.30. Suppose now there are 80 pairs of flows, with ten flows between the first and ninth rack, ten flows between the second and...
-
Consider the single switch VIAN in Figure 6.25, and assume an external router is connected to switch port 1. Assign IP addresses to the FE and CS hosts and router interface. Trace the steps taken at...
-
Suppose that all the switches in Figure 6.15 are replaced by hubs. All links are 100 Mbps. Now answer the questions posed in problem P23. Data From Problem 6.23 Consider Figure 6.15. Suppose that all...
-
18. Suppose that Maxima shares are selling for $10 per share and you own a call option to buy Maxima shares at $7.50. The intrinsic value of your option is:
-
ABC Insurance Company reported the following information on its accounting statements last year: What was ABC 's expense ratio last year
-
Calculate the current ratio and the quick ratio for the following partial financial statement for Tootsie Roll Note: Round your answers to the nearest hundredth
Study smarter with the SolutionInn App