# I thought that this would be right?

• June 29th, 2010, 02:27 PM
jwb4291
I thought that this would be right?
Here is the prompt I got: Suppose you have one cent (\$0.01) in a sock. Each day you double the amount of money you have in the sock. Thus on day one you have one cent, on day two 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 required for doubling; this value should be stored in the integer variable numDays.

Finish the doubleEachDay method below.
Code :

```public int doubleEachDay(double jackpot) { double amount = 0.01; int numDays = 0;   Finish the method here   return numDays; }```

So what I thought would work was
Code :

```while(double amount < jackpot){ amount=(amount*2); numDays++;```

but that gave me a weird error message
"compilation error (line 1, column 14):
'.class' expected"

So i feel like my code should have worked but obviously it didn't
• June 29th, 2010, 02:30 PM
Charlie
Re: I thought that this would be right?
We cant know what your error is without knowing whats on the line you get an error on is. Your code seems fine, but the error is somewhere else, prolly inside the main function where you run your stuff etc.

• June 29th, 2010, 02:39 PM
jwb4291
Re: I thought that this would be right?
This is the whole code. The error says that it should say '.class' right after 'double amount' which makes no sense
This is my most recent code that I plugged in in the blank space.
Code :

```while(amount > jackpot){ amount=(amount*2); numDays++;```
now in this I dont get an error but i get a regular feedback from the online program im using for school which just says.
The system has detected compilation errors. This could be caused by:
Missing semicolon ; at the end of a statement.
Unclosed braces {}.
Unclosed parentheses ().
Unterminated string literals "".
Invalid method signature.
Missing return statement.
Redeclared variable or data member.
etc.
So it could be any of those things
• June 29th, 2010, 02:52 PM
Charlie
Re: I thought that this would be right?
If thats all the code you have in your class, you havent declared the class. EVERY .java file you create is a CLASS. The compiled files' extension is even .CLASS. The absolute first thing you do when you make a new java program is to name the file, then write this piece of code:

Code :

```public class [B][I]FileName[/I][/B] {   //Code here, remember a main method if you want it to be runnable.   }```
• June 29th, 2010, 02:56 PM
jwb4291
Re: I thought that this would be right?
It is a homework assignment, the only place that I can actually type any code in is after
in numDays = 0;
code goes here
return numDays;
}
it is just completing the method but Im not sure what to put there because I thought what I was putting wouldve worked
• June 29th, 2010, 03:04 PM
Charlie
Re: I thought that this would be right?
Code :

```public int doubleEachDay(double jackpot) { double amount = 0.01; int numDays = 0;   while(amount [B][I]>[/I][/B] jackpot){ [B][I]<-- amount < jackpot, "is less than"[/I][/B] amount=(amount*2); numDays++; }   return numDays; }```

This method is now complete, if it doenst work; theres something else wrong with the class. The method declares everything it needs and it returns an int as promised. (Note the error you did in the while-loop)
• June 29th, 2010, 03:15 PM
jwb4291
Re: I thought that this would be right?
Quote:

Originally Posted by Charlie
Code :

```public int doubleEachDay(double jackpot) { double amount = 0.01; int numDays = 0;   while(amount [B][I]>[/I][/B] jackpot){ [B][I]<-- amount < jackpot, "is less than"[/I][/B] amount=(amount*2); numDays++; }   return numDays; }```

This method is now complete, if it doenst work; theres something else wrong with the class. The method declares everything it needs and it returns an int as promised. (Note the error you did in the while-loop)

Yeah that didnt work. This is the feedback I got
The input value for jackpot was 910.7072635769393

0

The correct solution produced:
17
• June 29th, 2010, 03:26 PM
Charlie
Re: I thought that this would be right?
Did you actually swap the > for a <?