Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use the screenshots when writing so I can have a better understanding also do ALL THE CLASSES Thanks in advance This lab aims to

Please use the screenshots when writing so I can have a better understanding also do ALL THE CLASSES Thanks in advance

This lab aims to provide experience in the use of abstract classes and interfaces. It specifically focuses on the following skills: 1. Writing and using interfaces and abstract methods 2. Completing concrete class implementations 3. Applying the Comparable and Comparator interfaces

THE PROBLEM . The Ministry of Labour plans to upgrade its System for Monitoring Labour (SML), while tracking earnings. They are particular interested in the activity of consultants (who may be either local or expatriate) as well as (local) nine-to-five employees (SML protocols currently do not support 9-5 expatriate positions). All local workers are expected to be citizens who have a TRN. All expatriates are expected to be registered and have an active work permit. All consultants are expected to earn from a skill. The SML data architect decides to model all potential workers as persons, with the knowledge that details like date representations and payment calculations will vary across groups. Your job during this lab is to assist the architect by writing one interface and three classes, as well as making adjustments to other classes.

MARKING CRITERIA (PLEASE REVIEW BEFORE STARTING)

Criterion Mark(s) Ability fully explain the definition and use of abstract classes and interfaces. 1 Demonstrable understanding the process of populating an instance of the superclass. 1 Knowledge of the effect of using the comparable and comparator interfaces 1 Ability to explain process of implementing customized orderings, including changing from ascending to descending order, and primary/secondary orderings 1 Coding style and readability. 1 A PENALTY OF 1 MARK WILL BE APPLIED FOR ANY OF THE FOLLOWING: - Ignoring specified interfaces or base classes based on the UML diagram (See Figure 1)

image text in transcribed

Figure 1: Simplified UML Class Diagram for SML Figure 1 depicts a simplified model of the classes that are needed to solve this problem. Your specific tasks include creating the RegisteredExpat interface, writing the LocalResource, LocalConsultant and SectorPayOrder classes, as well as making minor edits to other classes to demonstrate functionality. Note that to reduce risk of crashes you are required to uncomment sections of code that refer to yet unwritten classes, as classes are written.

LAB EXERCISES

Create interface RegisteredExpat. The interface should define one method named getWorkPermit that accepts no arguments, and returns a string.

Modify the ExpatConsultant class to ensure it correctly implements RegisteredExpat along with any other interface it currently implements. The work permit number of an expatriate consultant is obtained by joining the string WP00 with the id number of the expatriate consultant.

Write class LocalResource which extends the Person class. LocalResource exposes the following public methods:

a. LocalResource(String date, String sector)- Actions of the constructor include accepting a date in the format dd/mm/yyyy, initializing the base class, storing the sector and storing an id as a consecutively increasing integer. Note that the constructor must ensure that the date of birth information is recorded. b. getId():Integer - returns the ID of the current instance of LocalResource c. getSector():String returns the sector associated with the current instance of localResource d. getTRN():String returns the trn number of the current instance of LocalResource. The process used to determine the TRN is to add the id to the number 100000000 and then returning the string equivalent. e. Update the NineToFiver class to ensure it properly extends the LocalResource class f. In method getContact() of NineToFiver, remove the comments so that the method returns "Local Employee #"+and the id of the contact.

Write a concrete class LocalConsultant that extends LocalResource, and implements Citizen and Consultant. LocalConsultant exposes the following public methods: a. LocalConsultant(String dob, String sector, double skillPrice, double taxRate)

Saves local instance data populates superclass data and calculates and saves a permit tax for the instance with a value given by taxRate*skillPrice. b. earnFromSkill():double- return the skillPrice for the instance c. getContact():String return the string value obtained by joining the text LocalConsultant# with the id associated with the person d. getPay():double returns the value obtained by subtracting the permit tax from the value earned from the skill.

Assume that all paychecks are ready on the day of birth of the worker (ie all people born on the first of a month get paid on the first of a month, people born on the second get paid on the second, and so on). The SML managers want to track the cash flow in the system. Modify the SML driver class at the comment that is labeled //QUESTION 5 to include the code that will ensure the person list is sorted in ascending order of the day of birth.

Write a comparator for Person named SectorPayOrder that will allow a primary sort in ascending order of sector, and a secondary sort in ascending order of payrate where sectors match.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Figure 1 depicts a simplified model of the classes that are needed to solve this problem. Your specific tasks include creating the RegisteredExpat interface, writing the LocalResource, LocalConsultant and SectorPay0rder classes, as well as making minor edits to other classes to demonstrate functionality. Note that to reduce risk of crashes you are required to uncomment sections of code that refer to yet unwritten classes, as classes are written. \} 3 public class SML\{ public static void main(String[] args) throws IOException \{ BufferedReader bufferedReader = new BufferedReader (new InputStreamReader(System. in)); // TODO Auto-generated method stub double taxRate =0.15; Random r= new Random(); //comment the line below to have fun with test cases 4 and 5 r.setseed (7); ArrayList plist= new ArrayList> (); / /MOVE DOWN BEGINNING OF COMMENT BLOCK AFTER DOING WORK TO PASS TEST CASE if (test. equals("CASEO-Q1")) \{ ExpatConsultant ec 0= new ExpatConsultant("2/1/2001", "Computing", 200000, taxRate, 50000); if (ece instanceof RegisteredExpat) System.out. print ln(ec0); else \} System.out. println("RegisteredExpat not implemented"); //MOVE COMMENT BLOCK TO HERE TO PASS CASEO if (test. equals("CASE1-Q2")) \{ ExpatConsultant ec 0 = new ExpatConsultant("2/1/2001", "Computing", 200000, taxRate, 50000); System. out.println(ece.getWorkPermit()+";Birthday:"+eco.getDobDay ()+"/"+ece.getDobMonth()+"/"+eco.getDobYear()); \} //MOVE COMMENT BLOCK TO HERE TO PASS CASE1 taxRate =0.1 if (test. equals("CASE2-Q3")) \{ NineToFiver n50 = new NineToFiver ("2/1/2001", "Computing", 9,17,5, taxRate, 200); if (n50 instanceof LocalResource) \{ System.out.println("LocalResource implemented"); System.out.print ln(n50. getContact() +"; Birthday: "+n50. getDobDay()+"/"+n50.getDobMonth()+"/"+n50.getDobYear ()); System.out.print ln(n50);// "TRN:" +n50.getTRN() +"; working in the "+n50.getSector()+" sector, is paid ")

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

Database Systems Design Implementation And Management

Authors: Carlos Coronel, Steven Morris

14th Edition

978-0357673034

More Books

Students also viewed these Databases questions

Question

How does your language affect the way you think?

Answered: 1 week ago