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...
-
All six decision models from Chapter 9 rely on the appropriate timing and amount of cash flow. What are the potential errors a manager can make if this information is not accurate?
-
How many \(50 \mathrm{~W}\) panels will the owner require assuming battery storage is \(75 \%\) efficient and all loads are DC (no inverter)? a. For a stationary system "seeing" \(5 \mathrm{~h}\) of...
-
Jane White has recorded the following sales figures for last year for her business: January, $35,645; February, $35,456; March, $31,270; April, $32,129; May, $34,456; June, $35,256; July, $36,218;...
-
Examine one recent health-related judicial decision, or a health-related topic that is currently being litigated for the following:...
-
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...
-
Identify the strongest intermolecular force present in each substance. a. CH3OH b. (CH3)2CO c. N2
-
What circumstances allowed the frauds to happen (e.g., internal control failures, lack of background checks, missing policies and procedures)? Discuss and be specific.
-
A woman is not able to focus on objects that are closer to her eyes than \(400 \mathrm{~mm}\) unless she wears eyeglasses. Her glasses enable her to clearly see objects at the near point of an...
-
When adding categories to summarize data, you should perform all, except which of the following? A. Research payee business names on the Internet to gain a better understanding of what the payee...
-
Examples of input errors that make data analysis challenging include all of the following, except? A. QuikTrip, QuickTrip, QT, QwickTrp. B. Johnson, Johnson, Johnson. C. Durango, Durango, Dorango. D....
-
Data can be corrupted by which of the following? A. Everyday computer activity (e.g., errors in reading, writing, storing, processing data) B. Redundant data stored in more than one location C....
-
For the beam shown, determine the support reactions using superposition and procedure 1 from Sec.410. JA
-
During registration at Tech every quarter, students in the Department of Management must have their courses approved by the departmental advisor. It takes the advisor an average of 4 minutes...
-
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...
-
A B C 1) An object moves along the line from point 1 to point 2 in time t. 2 a) Suppose that the object is speeding up. Which of the labeled points A, B, or C could correspond to the location of the...
-
Identify two digital marketing methods that can be used for brand awareness and support with reasons. Define short-term and long-term goals for brand awareness in the digital marketing strategy. How...
-
Complete all boxes in the following table about atoms and monatomic ions Chemical symbol Atomic number Number of neutrons Number of electrons Net charge Chemical name Cu 47 +1 8 10 -2 30 Iron(II) ion
Study smarter with the SolutionInn App