Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

rart 3. The Externalcontractor Class Now you will create a class called ExternalContractor that also extends Employee. Be sure to create a test class for

image text in transcribed
image text in transcribed
image text in transcribed
rart 3. The Externalcontractor Class Now you will create a class called ExternalContractor that also extends Employee. Be sure to create a test class for ExternalContractor as well and test your methods as you write them. This class will have a three-parameter constructor, which should be passed through to Employee's constructor. Remember to utilize the information in the UML at the top of the lab. Contractors can elther be paid by the project or by hour. Since we can use Employee's getHourlyRate method if the contractor is paid by the hour, we need an overloaded method in the ExternalContractor class in case he/she is paid by the project. First you will overload the gethourlyRate method by having it take a single parameten a char representing the customer rank. A valid customer rank can be 'A' ' B; or 'C. An invalid customer rank would be any char besides ' A : ' B ', or ' C : invalid char should return $0. Use the guide below to return the correct hourlyRate values: Customer Rank = 'A: Pay rate =$38.50 Customer Rank = 'B' Pay rate =$41.75 Customer Rank = 'C, Pay rate =$5.50 A note about switch stotements. You may choose to write a switch statement instead of an if-else statement for this overlosded gethlourlyRate method. HI you're unfamilar to switch statements, below is an example of equivalent if -elke and switch statements: //if-else version if (x==4) \{ return 44 ; ) else if (x==5) return 55 ; ) elsel return 0 ; \} //equivalent switch statement switch (x)f case 4: return 44; case 5: return 55; default: return 0; Now you will overioad the weeklyPay method. Assume that an ExternalContractor works with a particular client on a weekly basis (no switching between projects within a work week). Within that week, the ExternalContractor may work a certain number of hours depending on the demand of the particular job. Therefore, your weeklyPay method will take two parameters: number of hours worked (int) and the customer rank (char). "The amount poid per week. " @param hours The number of hours worked per week. ' Eparam custRank The customer's rank (valid for ' A', 'B', 'C) - Preturn Returns the amount paid for a certain week. % public double weeklyPaylint hours, char custRank) You will want to calculate the weeklyPay by calling the overloaded gethourlyRate method you just wrote and pass the correct parameter. Then mulbiply that value with the number of hours worked and return the product. A quick note about the difference between overloating and overriding. Overloading occurs when two methods have the same name but have different parameters (resulting in different method signatures). For example a method called add that receives two int parameters would have a siggature addinit. int). This would be different from a method called add that receives two double parameters oddidouble, double). Same method name but different signature. Overriding occurs when we want to change the implementation of a method inherited from the superclass, This method would have the ame signature as the one inherited from the parent, i.e. has the same name and parameters, but has a different intemal implementation. We use the e overnide tag to indicate that we are overriding an inherited method. rart 3. The Externalcontractor Class Now you will create a class called ExternalContractor that also extends Employee. Be sure to create a test class for ExternalContractor as well and test your methods as you write them. This class will have a three-parameter constructor, which should be passed through to Employee's constructor. Remember to utilize the information in the UML at the top of the lab. Contractors can elther be paid by the project or by hour. Since we can use Employee's getHourlyRate method if the contractor is paid by the hour, we need an overloaded method in the ExternalContractor class in case he/she is paid by the project. First you will overload the gethourlyRate method by having it take a single parameten a char representing the customer rank. A valid customer rank can be 'A' ' B; or 'C. An invalid customer rank would be any char besides ' A : ' B ', or ' C : invalid char should return $0. Use the guide below to return the correct hourlyRate values: Customer Rank = 'A: Pay rate =$38.50 Customer Rank = 'B' Pay rate =$41.75 Customer Rank = 'C, Pay rate =$5.50 A note about switch stotements. You may choose to write a switch statement instead of an if-else statement for this overlosded gethlourlyRate method. HI you're unfamilar to switch statements, below is an example of equivalent if -elke and switch statements: //if-else version if (x==4) \{ return 44 ; ) else if (x==5) return 55 ; ) elsel return 0 ; \} //equivalent switch statement switch (x)f case 4: return 44; case 5: return 55; default: return 0; Now you will overioad the weeklyPay method. Assume that an ExternalContractor works with a particular client on a weekly basis (no switching between projects within a work week). Within that week, the ExternalContractor may work a certain number of hours depending on the demand of the particular job. Therefore, your weeklyPay method will take two parameters: number of hours worked (int) and the customer rank (char). "The amount poid per week. " @param hours The number of hours worked per week. ' Eparam custRank The customer's rank (valid for ' A', 'B', 'C) - Preturn Returns the amount paid for a certain week. % public double weeklyPaylint hours, char custRank) You will want to calculate the weeklyPay by calling the overloaded gethourlyRate method you just wrote and pass the correct parameter. Then mulbiply that value with the number of hours worked and return the product. A quick note about the difference between overloating and overriding. Overloading occurs when two methods have the same name but have different parameters (resulting in different method signatures). For example a method called add that receives two int parameters would have a siggature addinit. int). This would be different from a method called add that receives two double parameters oddidouble, double). Same method name but different signature. Overriding occurs when we want to change the implementation of a method inherited from the superclass, This method would have the ame signature as the one inherited from the parent, i.e. has the same name and parameters, but has a different intemal implementation. We use the e overnide tag to indicate that we are overriding an inherited method

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning C# 2005 Databases

Authors: Karli Watson

1st Edition

0470044063, 978-0470044063

More Books

Students also viewed these Databases questions