225k views
0 votes
Jobs Demo App Create a class named Job with the following data fields: description (this will contain values for example, "wash windows") time in hours (for example, 3.5) Hourly rate charged (for example, $25.00) Total fee (hourly rate times hours) - this will be a read only field. Note: Do not hardcode these values in the Job class, The values are meant to show you the type of data that the fields can take. For your Job class, include: Getter and/or setter for each field. Remember, the total fee— will be a read only field so you should provide mechanisms to calculate the value without the user of the class inadvertently overwriting it. Two constructors - one that takes no arguments, and another that can take description, time and hourly rate as arguments Write a program named DemoJobs. This is the class that will contain your Main method. The program should instantiate 2 Job objects and demonstrate its usage. For example, the first object uses the no argument constructor, sets values for the data fiels and prints the total fee for hours worked. The second object uses the constructor that takes 3 arguments. Also, print the total fee in this case too.

1 Answer

6 votes

Final answer:

To create the Jobs class, define data fields and getter/setter methods. Instantiate two Job objects in the DemoJobs class and print the total fee for each.

Step-by-step explanation:

To create the Jobs class, you will need to define the following data fields: description, time in hours, hourly rate charged, and total fee. You should include getter and/or setter methods for each field. The total fee field should be read-only and calculated based on the hourly rate and time in hours.

For example, if the description is 'wash windows', the time in hours is 3.5, and the hourly rate is $25.00, the total fee would be $87.50. In this example, job1 is created using the no-argument constructor and then setting each property, whereas job2 is created directly with the specified constructor. The getTotalFee method, which is read-only, calculates the total fee for the job. This meets the requirement that the Total fee is a read-only field.

In the DemoJobs class, instantiate two Job objects, one using the no-argument constructor and the other using the constructor that takes description, time, and hourly rate as arguments. Print the total fee for each object to demonstrate their usage.

User Josh K
by
8.3k points