Visual C# (Made in a Console App) 11.3 (Composition vs. Inheritance) Many apps written with inheritance could
Fantastic news! We've Found the answer you've been seeking!
Question:
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 BasePlusCommissionEmployee (Fig. 11.11) of the CommissionEmployee-BasePlusCommissionEmployee hierarchy to use composition rather than in-heritance.
Transcribed Image Text:
Derived Class BasePlus Commission Employee Class BasePlus Commission Employee (Fig. 11.11) has several changes to its method imple- mentations that distinguish it from the version in Fig. 11.9. Methods Earnings (Fig. 11.11, line 43) and ToString (lines 46-47) each invoke property Base Salary s get accessor to obtain the base-salary value, rather than accessing baseSalary directly. If we decide to rename instance variable baseSalary, only the body of property BaseSalary will need to change. I // Fig. 11.11: BasePlus Commission Employee.cs 2 // BasePlusCommission Employee inherits from Commission Employee and has // controlled access to Commission Employee s private data via // its public properties. using System; te lines 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 public class BasePlus Commission Employee Commission Employee { private decimal baseSalary; // base salary per week // six-parameter derived-class constructor // with call to base class Commission Employee constructor public BasePlus Commission Employee (string firstName, string lastName, string social SecurityNumber, decimal gross Sales, decimal commission Rate, decimal baseSalary) : base (firstName, lastName, social SecurityNumber, grossSales, commission Rate) BaseSalary baseSalary; // validates base salary { } mo)logusn} // property that gets and sets // BasePlus Commission Employee s base salary public decimal BaseSalary { get { } set { return baseSalary; sulsy couleversanotaaimmo if (value < 0) // validation { 15311 Man oring Fig. 11.11 BasePlusCommission Employee inherits from Commission Employee and has access to Commission Employee s private data via its public properties. (Part I of 2.) 35 36 37 38 39 40 31 12 43 14 -5 6 7 8 } throw new ArgumentOutOfRange Exception (nameof (value), value, ${nameof (BaseSalary)} must be >= 0 ); baseSalary = value; // calculate earnings public override decimal Earnings () => Base Salary + base. Earnings(); // return string representation of BasePlusCommission Employee public override string ToString() => $ base-salaried {base.ToString()}base salary: {BaseSalary:C} ; .11.11 | BasePlus Commission Employee inherits from Commission Employee and has ess to Commission Employee s private data via its public properties. (Part 2 of 2.) Derived Class BasePlus Commission Employee Class BasePlus Commission Employee (Fig. 11.11) has several changes to its method imple- mentations that distinguish it from the version in Fig. 11.9. Methods Earnings (Fig. 11.11, line 43) and ToString (lines 46-47) each invoke property Base Salary s get accessor to obtain the base-salary value, rather than accessing baseSalary directly. If we decide to rename instance variable baseSalary, only the body of property BaseSalary will need to change. I // Fig. 11.11: BasePlus Commission Employee.cs 2 // BasePlusCommission Employee inherits from Commission Employee and has // controlled access to Commission Employee s private data via // its public properties. using System; te lines 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 public class BasePlus Commission Employee Commission Employee { private decimal baseSalary; // base salary per week // six-parameter derived-class constructor // with call to base class Commission Employee constructor public BasePlus Commission Employee (string firstName, string lastName, string social SecurityNumber, decimal gross Sales, decimal commission Rate, decimal baseSalary) : base (firstName, lastName, social SecurityNumber, grossSales, commission Rate) BaseSalary baseSalary; // validates base salary { } mo)logusn} // property that gets and sets // BasePlus Commission Employee s base salary public decimal BaseSalary { get { } set { return baseSalary; sulsy couleversanotaaimmo if (value < 0) // validation { 15311 Man oring Fig. 11.11 BasePlusCommission Employee inherits from Commission Employee and has access to Commission Employee s private data via its public properties. (Part I of 2.) 35 36 37 38 39 40 31 12 43 14 -5 6 7 8 } throw new ArgumentOutOfRange Exception (nameof (value), value, ${nameof (BaseSalary)} must be >= 0 ); baseSalary = value; // calculate earnings public override decimal Earnings () => Base Salary + base. Earnings(); // return string representation of BasePlusCommission Employee public override string ToString() => $ base-salaried {base.ToString()}base salary: {BaseSalary:C} ; .11.11 | BasePlus Commission Employee inherits from Commission Employee and has ess to Commission Employee s private data via its public properties. (Part 2 of 2.)
Expert Answer:
Answer rating: 100% (QA)
Answer USe this code using composition not inheritance using System public class CommissionEmployee private string firstName private string lastName private string socialSecurityNumber private decimal ... View the full answer
Related Book For
Database Systems Design Implementation and Management
ISBN: 978-1337627900
13th edition
Authors: Carlos Coronel, Steven Morris
Posted Date:
Students also viewed these electrical engineering 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...
-
In many code-law countries, registration rather than prior use establishes ownership of intellectual property rights. Comment.
-
In many polynomial regression problems, rather than fitting a "centered" regression function using x' = x - xÌ, computational accuracy can be improved by using a function of the standardized...
-
In a survey of 106 college students, data were gathered on the number of piercings each student had and the number of classes they had skipped in the past 3 weeks. We want to determine whether there...
-
Suppose you own a restaurant that serves only dinner. You are trying to decide whether or not to rent out your dining room and kitchen during mornings to another firm, The Breakfast Club, Inc. That...
-
A firm is assigned the network part 128.171. It selects a 10-bit subnet part. a. Draw the bits for the four octets of the IP address of the first host on the first subnet. b. Convert this answer into...
-
Identify each of the following as land (L) or land improvements (LI): 1. Survey fees 2. Fencing 3. Lighting 4. Clearing land 5. Parking lot
-
Two soft-drink producers, York Cola and Reno Cola, secretly collude to fix prices. Each firm must decide whether to abide by the agreement or to cheat on it. The payoff matrix is as follows: a. What...
-
Find Vacant 2022, and monthly supply MS using the following: Vacant2021 = 4m SF. Construction2022 = 6m SF. Net Absorption2022 = 1m SF. Gross Absorption2022 = 2.5m SF.
-
During 2001, many European markets for mobile phones reached saturation. Because of this, mobile phone operators started to shift their focus from growth and market share to cut-ting costs. One way...
-
The following data are available for the ABC Manufacturing Company for the year 2010, its first year of operations: Beginning inventory in units Units produced Units sold Sales Material cost (unit...
-
What are the molecular mechanisms underlying apoptosis, and how do they regulate programmed cell death in multicellular organisms ?
-
Gordon's Freight Company is looking to develop a new strategic plan. Colin Alexander has been developing a project plan and has identified the following tasks, precedence relations, normal task...
-
Peter's Curling Inc. operates several curling centres for games and equipment sales. The following transactions occurred in October of the current year: a. Peter's collected $15,250 from customers...
-
The Polaris Company uses a job-order costing system. The following transactions occurred in October: a. Raw materials purchased on account, $210,000. b. Raw materials used in production, $190,000...
-
1.You have decided to host a discussion about post-traumatic stress disorder with the families of soldiers abroad. 2.Provide an overview of the disorder, the symptoms, and consequences of PTSD.
-
Fictional country Gondal2 is choosing to borrow and lend with the rest of the world. It is small, so its actions have no effect on the world interest rate, which is r = 0.21 between period 1 and 2....
-
Based on the scenario described below, generate all possible association rules with values for confidence, support (for dependent), and lift. Submit your solutions in a Word document (name it...
-
How would you describe a condition in which one attribute is dependent on another attribute when neither attribute is part of the primary key?
-
Using an example, illustrate the concepts of class and class instances.
-
A table is in ___3rd___ normal form when it is in ___2 nd normal form___ and there are no transitive dependencies.
-
Audits can be categorized into five types: (1) financial statement audits, (2) audits of internal control, (3) compliance audits, (4) operational audits, and (5) forensic audits.
-
Cendant Corporation (Cendant). On December 17, 1997, CUC International merged with HFS Incorporated to form Cendant. Cendant operates primarily in three business segmentsalliance marketing, travel,...
-
Sandy Pitts is auditing Hofmeister Hardware Company, a fast-growing retail hardware chain in the Atlanta area. While Pitts has previously worked on this engagement, this is her first year as the...
Study smarter with the SolutionInn App