Question: Java Programming 1. An employer hires two students, a CS major and an XX major to do handyman work under the following conditions: The duration
Java Programming
1. An employer hires two students, a CS major and an XX major to do handyman work under the following conditions:
The duration of the job is between 21 and 30 days, each choice is equally likely
There are two options of payment offered to the workers: the employer pays
(i) $1,000.00 for each day of work
(ii) 1 penny for the first day and for each other day the payment is twice as many pennies as paid for the previous days work
The XX major took option 1, the CS major chose the second option. Did XX or CS make a better deal? What is the minimum, the maximum and the average money each student can make considering the possible cases of 21 to 30 working days? You have to write a program to answer these question.
2. The main method has the following responsibilities:
Creates a Scanner object to read from the console
Solicits an integer number between 21 and 30
Validates the required bounds for the input (we assume that the input is a number). Use a loop for solicitation until input is admissible.
Saves the input in a variable named days
Declares integral type variable pennies, xxMin, xxMax, xxAverage, csMin, csMax, csAverage, sumOfPennies
Runs a for loop that iterates days many times
For the first day, pennies is assigned 1, for each subsequent day pennies is doubled; you must not use the Math,pow( ) method to compute the values for the pennies variable. At each turn of the iteration the day index and the pennies value are displayed on the console according to the template (notice the comma separation), day 20: xyz,abc Use the printf( ) method with the comma separator for the display Hint: see pp 170 171 (168 169 in Edition 5) for using the comma separator flag
At each turn of the loop the sumOfPennies variable accumulates the daily payments pennies from day 1 to the current day
When the iteration is finished, declare a double variable wages and assign it the dollar value that corresponds to sumOfPennies
Display the dollar total on the console. The display shall follow the template In 10 days the CS major earned $5.12 Use the comma separator again
. Run a for loop that iterates 30 times. Use this loop
(i) to compute csMin (the sumOfPennies value at day 21)
(ii) to compute csMax (the sumOfPennies at day 30)
(iii) to compute csAverage (add the sumOfPennies values of days 21, 22, , 30 and divide by 10).
After the loop compute xxMin, xxMax, xxAverage (no loop needed)
Display all the min, max and average values on the console
3.Create a testing plan (it does not have to be documented): the input validation must work correct as well as the penny iteration; run the program for various input values to see that it is free of bugs
4. Sum up your experience in a comment attached to the code. In this comment analyze if the choice made by the CS major was justifiable, which may depend on the number of days worked.
5. Save your comments (the whole text) in a String variable named comment
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
