Question: a Java program that calculates how much a person earns in a month if the salary is one penny the first day, two pennies the

a Java program that calculates how much a person earns in a month if the salary is one penny the first day, two pennies the second day, four pennies the third day, and continue to double each day the employee works. The program keeps doing it until the user enters N from the keyboard.

The program should ask the user for the number of days the employee worked during the month and should display a table showing how much the salary was for each day worked, as well as the total pay earned for the month. Do not accept a number less than 1 or more than 31 for the number of days worked. The output should be displayed in dollars with two decimal points, not in pennies.

Hint:Use the NumberFormat class to format the total with the $ sign and the DecimalFormat to format the pay in the table to two decimal places.

Finally, ask the user "Do you want to do it again: Enter Y for yes and N for no". If the user enters N then the program terminates otherwise prompts again for the number of days.

Example output with valid input :

How many days did the employee work this month? 3

Day Pay

------------------

1 0.01

2 0.02

3 0.04

------------------

Total $0.07

Do you want to do it again: Enter Y for yes and N for no: Y

How many days did the employee work this month? 8

Day Pay

------------------

1 0.01

2 0.02

3 0.04

4 0.08

5 0.16

6 0.32

7 0.64

8 1.28

------------------

Total $ 2.55

Do you want to do it again: Enter Y for yes and N for no: N

Goodbye!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Heres a Java program that implements the described functionali... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!