Question

Write a Java Program(DoublePenny.java) that calculates the amount after a penny has been doubled every day...

Write a Java Program(DoublePenny.java) that calculates the amount after a penny has been doubled every day for a 30-day month. Use a while loop to carry out the calculation. Display the amount. Sample output below if the statement was something like

System.out.println(“After day “ + day + “ you have “ + money);

After day 2 you have 0.02

After day 3 you have 0.04

After day 4 you have 0.08 ……………

After day 30 you have 5368709.12

0 0
Add a comment Improve this question Transcribed image text
Answer #1
public class DoublePenny {

    public static void main(String[] args) {
        int day = 1;
        double money = 0.01;
        while (day <= 30) {
            System.out.println("After day " + day + " you have " + money);
            day++;
            money *= 2;
        }
    }
}

Add a comment
Know the answer?
Add Answer to:
Write a Java Program(DoublePenny.java) that calculates the amount after a penny has been doubled every day...
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
  • 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...

  • 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...

  • 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...

  • 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...

  • 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...

  • a. Create the logic for a program that calculates and displays the amount of money you...

    a. Create the logic for a program that calculates and displays the amount of money you would have if you invested $5000 at 2 percent simple interest for one year. Create a separate method to do the calculation and return the result to be displayed. b. Modify the program in Exercise 3a so that the main program prompts the user for the amount of money and passes it to the interest-calculating method. c. Modify the program in Exercise 3b so...

  • Write a program that calculates the calories burned while running over a given number of miles....

    Write a program that calculates the calories burned while running over a given number of miles. While several factors determine how many calories are burned during a mile run, for this program, 90 calories are burned for every mile of running. The cumulative calories burned during a run can be calculated as: Calories * Distance For example, if a person runs 5 miles, the total calories burned is 450. After 3 hours, the person has burned 2 calories. The program...

  • I have a Java question. (I'm using BlueJ.) I'm trying to program something that calculates pay...

    I have a Java question. (I'm using BlueJ.) I'm trying to program something that calculates pay roll. Most of it works, but I've identified two parts that don't: It labels all salaries as "Fulltime" no matter how many hours worked I input, and the do/while loop does something weird. The if/else statement I have for the fulltime vs part time is: if (hoursWorked < 40.0) { position = partTime; } else if (hoursWorked >= 40.0 || hoursWorked <= 168.0) {...

  • Write a small JAVA program that continually reads in user values and calculates the average of all values. The program s...

    Write a small JAVA program that continually reads in user values and calculates the average of all values. The program should first ask the user for the number of values to be entered. Upon storing this value, the program should proceed to read in that amount of values. What will be the best strategy here? a suggestion would be only calculating the average after you know you have read in all values. You can expect to use some type of...

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
Active Questions
ADVERTISEMENT