Question

Suppose you have one cent ($0.01) in a piggy bank. Each day you double the amount of money you have in the bank. Thus at the beginning - day zero - you have one cent, on day one you have two cents (0.02), on day three you have four cents (0.04) and so forth. The doubleEachDay method takes a double value, jackpot, as its input argument, and calculates the number of days needed to reach or exceed the jackpot amount, starting at 0.01 and doubling each day. The method returns the number of days, numDays, required for doubling. Notice that we have already provided the methods return statement. Finish the doubleEachDay method below. public int doubleEachDay(double jackpot) { double amount = 0.01; int numDays 0; return numDays; //end method CHECK ANSWER

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

Question 1

Answer:

public int doubleEachDay(double jackpot) {

double amount = 0.01;

int numDays = 0;

while(amount <= jackpot) {

amount = amount * 2;

numDays++;

}

return numDays;

}

Question 2

Answer:

int n=5;

while(n < 10000) {

System.out.println(n);

n = n * 5;

}

Add a comment
Know the answer?
Add Answer to:
Suppose you have one cent ($0.01) in a piggy bank. Each day you double the amount...
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
  • Is it better to receive 50,000$ per day for 30 days(1 month) or to receive one...

    Is it better to receive 50,000$ per day for 30 days(1 month) or to receive one penny on first day and have the amount you receive double each day for the month. On day 1 you will receive 1 cent. On day 2 you will receive 2 cents and have 3 cents in total. On day 3 you will receive 4 cents and have 7 cents in total. On day 4 you will receive 8 cents and have 15 cents...

  • a) [2 points.] Suppose you have a project that has a 70 per cent chance of...

    a) [2 points.] Suppose you have a project that has a 70 per cent chance of doubling and a 30 per cent chance of halving your investment in a day. (This is a high-risk project indeed.) i. Compute the expected return and volatility of a one-period investment. ii. Compute the expected return per day, given that you can renew the project each day for a very long period of time in principle infinitely). b) If a security lies above the...

  • Congratulations, you have been hired by Shaky Bank and Trust as a staff programmer. Your task...

    Congratulations, you have been hired by Shaky Bank and Trust as a staff programmer. Your task for this assignment is to create a simple bank accounting system and demonstrate its use. Create an Account class as per the following specifications: three private instance variables: accountOwnerName (String), accountNumber (int) and balance (double) a single constructor with three arguments: the account owner's name, accountNumber and starting balance. In the constructor, initialize the instance variables with the provided parameter values. get and set...

  • <!DOCTYPE html> <html> <body> <script> // // Write a function that calculates the amount of money...

    <!DOCTYPE html> <html> <body> <script> // // Write a function that calculates the amount of money a person would earn over // a period of years 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 years and call the function which will return the total // money earned in dollars and cents, not pennies. Assume...

  • Please help JAVA Part II: Programming Module (80 marks): Write a banking program that simulates the operation of your l...

    Please help JAVA Part II: Programming Module (80 marks): Write a banking program that simulates the operation of your local bank. You should declare the following collection of classes: 1) An abstract class Customer: each customer has: firstName(String), lastName (String), age (integer), customerNumber (integer) - The Class customer has a class variable lastCustomerNumber that is initialized to 9999. It is used to initialize the customerNumber. Hence, the first customer number is set to 9999 and each time a new customer...

  • Suppose the bank wanted to keep track of the total number of deposits and withdrawals (separately)...

    Suppose the bank wanted to keep track of the total number of deposits and withdrawals (separately) for each day, and the total amount deposited and withdrawn. Write code to do this as follows: Add a public toString method to the class so that Account objects can be easily printed. Test that this works by adding a main method to Account that creates and prints two Account objectsvia println statements. Provide the transcript in the lab document. Add four private static...

  • Step One This is the Measurable interface we saw in class; you will need to provide...

    Step One This is the Measurable interface we saw in class; you will need to provide this class; this is it in its entirety (this is literally all you have to do for this step): public interface Measurable double getMeasure(); Step Two This is the Comparable interface that is a part of the standard Java library: public interface Comparable int compareTo (Object otherObject); Finish this class to represent a PiggyBank. A PiggyBank holds quarters, dimes, nickels, and pennies. You will...

  • JAVA: amortization table: Hi, I have built this code and in one of my methods: printDetailsToConsole...

    JAVA: amortization table: Hi, I have built this code and in one of my methods: printDetailsToConsole I would like it to print the first 3 payments and the last 3 payments if n is larger than 6 payments. Please help! Thank you!! //start of program import java.util.Scanner; import java.io.FileOutputStream; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.lang.Math; //345678901234567890123456789012345678901234567890123456789012345678901234567890 /** * Write a description of class MortgageCalculator here. * * @author () * @version () */ public class LoanAmortization {    /* *...

  • In this lab, a piece of working software is given. You are asked to make changes...

    In this lab, a piece of working software is given. You are asked to make changes to the software according to some requirement. The scenario in this lab mimics the situation that most old software applications are facing---need to update. When covering inheritance and polymorphism, we introduced a pattern that has three elements: instanceof operator, base pointers, and a collection data structure. In the given code, the collection used is a dynamic array (will change its length automatically) called Vector....

  • Suppose that you have several numbered billiard balls on a pool table. The smallest possible number...

    Suppose that you have several numbered billiard balls on a pool table. The smallest possible number on the ball is “1”. At each step, you remove a billiard ball from the table. If the ball removed is numbered n, you replace it with n balls randomly numbered less than n. For example, if you remove the “5” ball, you replace it with balls numbered “2”, “1”, “1”, “4”, and “3”, where numbers 2, 1, 1, 4, and 3 were randomly...

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
ADVERTISEMENT