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
Step: 1
Heres a Java program that implements the described functionali...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