Question
Java: UseWorker: // this class demonstrates the use of the Worker class. // you may not modify this file other than section (3) // public
Java:
UseWorker:
// this class demonstrates the use of the Worker class.
// you may not modify this file other than section (3)
//
public class UseWorker
{
public static void main(String[] args)
{
// (1) Sample code run
System.out.println("-- Sample output starts... -- ");
Worker anil = new Worker("Anil");
Worker jasmin = new Worker("Jasmin", 18.25, 25);
Worker fred = new Worker("Fred", 16.00, 40, 1, true);
anil.printRev();
jasmin.printRev();
fred.printRev();
jasmin.setType(0); // set her to part-time from unknown
System.out.println(" -----------------");
System.out.println(anil);
System.out.println("-----");
System.out.println(jasmin);
System.out.println("-----");
System.out.println(fred);
System.out.println(" -----------------");
System.out.printf("Anil's pay : $%6.2f ", anil.computePay());
System.out.printf("Jasmin's pay: $%6.2f ", jasmin.computePay());
System.out.printf("Fred's pay : $%6.2f ", fred.computePay());
System.out.println(" -- Sample output ends :) --");
// (2) ======================== Sample output ends =========================
// no changes to code below
System.out.println(" =========================");
Worker joe = new Worker("Joe", 10, 101, 1, true);
System.out.println(joe);
System.out.printf("** Joe's pay : $%6.2f ", joe.computePay());
System.out.println(" =========================");
jasmin.setHours(-1);
System.out.println(jasmin);
System.out.println(" =========================");
anil.setType(-2);
System.out.println(anil);
System.out.println(" =========================");
fred.setPay(-10.25);
System.out.println(fred);
System.out.printf("** Fred's pay : $%6.2f ", fred.computePay());
// (3) ================== NO CHANGES ABOVE THIS LINE ================== //
// Create an object using your first name and give it values of your choice.
// Then print out your own object using System.out.println(). I.e., two lines
// of code total - no other changes to this source file.
// Your code starts here:
System.out.println(" The End.");
}
}
You will create two classes. If identifiersames 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 forPrivate data fields 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. Don't assume a method prints something unless says so. For each, carefully identify return type, and number/types of possible parameters Constants Constructor(s) Setters/getters Helper code 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 wType work type, an integer (1full-time, o part-time, -1-unknown) (default-1) retired whether or not the Worker is retired, can only be true or false (default false) (default o) 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 variableStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started