Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java: You will create two classes. If identifiers/names are specified, you must use them, and you must use the standard order of declaration as shown

Java:

You will create two classes. If identifiers/names are specified, you must use them, and you must use the standard order of declaration as shown on the right. All error messages must go to System.err as usual . Responsibilities for code are divided up between the two classes, to earn maximum credit follow the instructions closely so not to mix these up. All methods have to be documented. Dont assume a method prints something unless says so. For each, carefully identify return type, and number/types of possible parameters.

Worker class:

Constants

MAX_HOURS maximum hours a worker can work set to 100

Data Fields highlight the validity rules for each - you will need them below.

fName first name of the Worker

hPay hourly pay rate, must be greater than zero, can have decimal values (default 0.0)

hours the number of hours the worker has worked so far this week. Whole numbers only. Valid values are zero or greater, cant be more than MAX_HOURS. (default 0)

wType work type, an integer (1 = full-time, 0 = part-time, -1 = unknown) (default -1)

retired whether or not the Worker is retired, can only be true or false (default false)

Constructors

For all constructors, verify the data is in the valid range, otherwise ignore it and leave the default values.

Constructor with only the name as a parameter

Constructor with the first name, pay and hours as parameters assume the pay and hours are valid

Constructor with all fields as parameters you must check that the hours, pay and type are valid, if not, set default values (if not already set).

Getters each method returns the value stored in the particular field.

getfName

getPay

getHours

getType returns the appropriate integer

isRetired returns the value of the retired instance variable.

Setters

setName

setPay verify the parameter is valid, if not ignore, leave current value unchanged.

setHours Must check that the number passed as a parameter is valid a worker cannot have more than MAX_HOURS hours or less than zero. If the number is not valid, leave the current number of hours unchanged and print a specific informative error message mentioning the name of the person and the bad value. E.g., Invalid type for Jasmin: 5 (remember, you have access to all of the instance variables from inside the class, so you can just refer to fName :)

setType Must check that the number passed as a parameter is valid a worker can only be full- or parttime, do not accept unknown or any other type. If the number is not valid, leave the current type unchanged and print a specific informative error message. Same as above, mention the name and invalid value.

setRetired set to true or false depending if retired or not

Utility Functions

computePay() Returns the pay due to the worker based on her hourly pay and the hours she has worked. There is no printing in this method, you are simply computing and returning a value.

printRev() Print the name of the Worker in reverse. E.g., Jasmin -> nimsaJ. Requirement: You must loop through the String, character by character from the end to the start. All your output has to be on the same line, followed by a newline.

toString() Returns a string used to print all of the data fields of the class, one per line, but no final newline. Each data item has a label identifying it. To convincingly demonstrate your ability to format strings your output format must match mine. You must spell out the work type, i.e., instead of using a number to identify full-time vs part-time or unknown, use one of these descriptive strings instead: full-time, part-time, unknown.

typeToStr() (optional but highly recommended) returns the value of the wType instance variable as one of the descriptive strings: full-time, part-time, unknown. Useful for toString()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions

Question

What does stickiest refer to in regard to social media

Answered: 1 week ago