Question

Write a Java program that calculates how much a person would earn after a period of...

Write a Java program that calculates how much a person would earn after a period of time, according to the following rules:

1. The starting salary for the first day is $1.

2. The salary will double each day.

Ask the user to input the number of days worked. The output should display how much the salary was for each day worked, and show the total pay at the end of the work period. Get output similar to the sample output below. Restrictions: don't accept a number less than 1 for input (the person should work at least one day).

SAMPLE OUTPUT: How many days worked? -9 ERROR! Should be positive. REENTER: 12

0 0
Add a comment Improve this question Transcribed image text
Answer #1

In this Java Program

- We are accepting an integer to get working days and storing it in numberOfDaysWorked variable.

- Then for each day, salary is being double.

- We are printing the salary for every day as well as the overall salary

- If the user enters negative value or less than 1, we are printing the Error statement and again accepting the numberOfDaysWorked until the user enters the correct one.

- Finally, after printing to the connsole, program is being termianted

Program:

import java.util.Scanner;
public class Salary
{
   public static void main(String[] args)
   {
       Scanner src=new Scanner(System.in);
       int startingsalary=1;
       int incrementSalary=0;
       boolean flag=true;
       while(flag)
       {
           System.out.print("How many days worked? ");
           int numberOfDaysWorked=src.nextInt();
           if(numberOfDaysWorked>=1)
           {
               for(int i=1;i<=numberOfDaysWorked;i++)
               {

                   System.out.println("Day" +i + "\tSalary is $" + startingsalary);
                   incrementSalary += startingsalary;
                   startingsalary = startingsalary * 2;
               }
               System.out.println("The Total pay: $"+incrementSalary);
               flag=false;
           }
           else
           {
               System.out.println("ERROR! Should be positive");
               flag=true;
           }
       }
   }
}

Output:

Hope this Helps!!!

If not please comment, I will Help you with that..

Add a comment
Know the answer?
Add Answer to:
Write a Java program that calculates how much a person would earn after a period of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Java. Use the concept of LOOPS: 2.Write a program that calculates the amount a person...

    In Java. Use the concept of LOOPS: 2.Write a program that calculates the amount a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day, and continues to double each day. The program should display a table showing the salary for each day, and then show the total pay at the end of the period. The output should be displayed in a dollar amount, not the...

  • In 80x86 assembly language Write a program that calculates how much a person earns in a...

    In 80x86 assembly language Write a 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 so on with the daily pay doubling each day the employee works. The program should ask the user for the number of days the employee worked during the month, validate that it is between 1 and 31, and then display a table showing...

  • Write a program that calculates the amount a person would earn over a 30-day period of...

    Write a program that calculates the amount a person would earn over a 30-day period of time if his/her salary is one penny the first day, two pennies the second day, and continues to double each day. The program should display a table showing the salary for each day, and then show the total pay at the end of the period. The output should be displayed in a dollar amount, not the number of pennies. A sample output might look...

  • Week 5 Project Write a program that calculates the amount of money a person would earn...

    Week 5 Project Write a program that calculates the amount of money a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day, four pennies the third day, and continues to double each day. Output the amount earned each day .. and the total pay at the end. The Algorithm (Plan) for your program would be: Ask the user for the number of days to be...

  • Write a program using Python that calculates the amount of money a person would earn over...

    Write a program using Python that calculates the amount of money a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day, and continues to double each day. The program should ask the user for the number of days. Display a table showing what the salary was for each day, then show the total pay at the end of the period. The output should be displayed...

  • Using Javascript! Write a program that calculates the amount of money a person would earn over...

    Using Javascript! Write a program that calculates the amount of money a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day, and continues to double each day. The program should ask the user for the number of days. Display a table showing what the salary was for each day, and then show the total pay at the end of the period. The output should be...

  • Python Computer Programming Write a program that calculates the amount of money a person would earn...

    Python Computer Programming Write a program that calculates the amount of money a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day, and continues to double each day. The program should ask the user for the number of days. Display a table showing what the salary was for each day, then show the total pay at the end of the period. The output should be...

  • Show Me The Money. (15 points) Write a C++ program that calculates how much a person...

    Show Me The Money. (15 points) Write a C++ 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 so on, with the daily pay doubling each day the employee works. 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...

  • HTML only Design and implement a program that calculates the amount of money a person would...

    HTML only Design and implement a program that calculates the amount of money a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day, and continues to double each day. The program should:ask the user for the number of daysdisplay a table showing what the salary was for each daythen show the total pay at the end of the period.The output should be displayed in the...

  • Project 5 - intro to python Write a program in python that calculates the amount of...

    Project 5 - intro to python Write a program in python that calculates the amount of money a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day, four pennies the third day, and continues to double each day. Output the amount earned each day .. and the total pay at the end. The Algorithm (Plan) for your program would be: Ask the user for the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT