codyland

06-28-2008, 11:05 AM

My professor gave us the following assignment:

Write a Java program to compute the number of days for the following scheme. The recipient receives a penny on day 1 and the amount is doubled on subsequent days. That is on day 2 the amount received is 2, on day three 4 pennies, day four 8 pennies and so on. The recipient accumulates the amount received. Write a program to compute how many days will it take for the recipient to accumulate more than 100 dollars.

Here is the code i came up with but continue to receive errors when compiling...what is wrong? :-( :confused:

import java.util.*;

public class assignment4 {

public assignment4() {

}

public static void main(String[] args);{

}

int dailyAmount, numberOfDays;

double totalAmount;

Scanner keyboard = new Scanner(System.in);

totalAmount = 0;

dailyAmount = 1;

numberOfDays = 1;

while (totalAmount <= 100)

{

totalAmount = dailyAmount*2;

numberOfDays++;

dailyAmount = dailyAmount*2;

}

if (totalAmount >= 100)

System.out.println("The total number of days it took for the balance to equal $100 was" + (numberOfDays));

}

Thank you in advance for any help you can give...

Write a Java program to compute the number of days for the following scheme. The recipient receives a penny on day 1 and the amount is doubled on subsequent days. That is on day 2 the amount received is 2, on day three 4 pennies, day four 8 pennies and so on. The recipient accumulates the amount received. Write a program to compute how many days will it take for the recipient to accumulate more than 100 dollars.

Here is the code i came up with but continue to receive errors when compiling...what is wrong? :-( :confused:

import java.util.*;

public class assignment4 {

public assignment4() {

}

public static void main(String[] args);{

}

int dailyAmount, numberOfDays;

double totalAmount;

Scanner keyboard = new Scanner(System.in);

totalAmount = 0;

dailyAmount = 1;

numberOfDays = 1;

while (totalAmount <= 100)

{

totalAmount = dailyAmount*2;

numberOfDays++;

dailyAmount = dailyAmount*2;

}

if (totalAmount >= 100)

System.out.println("The total number of days it took for the balance to equal $100 was" + (numberOfDays));

}

Thank you in advance for any help you can give...