my dog learned polymorphism*
The moose likes Beginning Java and the fly likes Homework help please!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Homework help please!!" Watch "Homework help please!!" New topic
Author

Homework help please!!

Jessica Curtner
Greenhorn

Joined: Mar 22, 2009
Posts: 2
hello, I am a little stuck on a homework assignment, "Pennies for Pay" basically i have to write a program using a loop that will calculate a persons earnings over a period of time. The person will earn a penny the first day, 2 pennies the second day and continues to double each day and show a table displaying the salary for each day and total pay at the end of the period... My problem is the output i am getting is different than it should be see below:

run:
How many days did you work?
5
Days Worked Amount Paid
--------------------------------------------
1 0.02 <--This should be 1
2 0.04
3 0.08
4 0.16
5 0.32
Your total pay is
$1.62
BUILD SUCCESSFUL (total time: 3 seconds)


Am i doing something wrong with the increment or am i multiplying wrong?? PLEASE HELP!!



Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
I edit because my answer was not correct.

To see why the result in the first case is 0.02 instead of 0.01 you have to check what are you doing in line 45. What value has currentpay in the first loop? and what value are you asigning? maybe and aditional check is neccesary there ;)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39416
    
  28
I can see what has happened, but you will need additional information to see it yourself.

Insert the following line in your code, after line 44 and before line 45:and this after the present line 47:Note the two lines are very similar

Why are you using DecimalFormat rather than the printf methods? What will happen if somebody enters 0 as number of days worked?

Don't anybody give a complete answer: read this FAQ.
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
Ey Campbell, you are fast, I was editting my answer

If someone inserts 0 there is a check at line 35
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39416
    
  28
Albareto McKenzie wrote:Ey Campbell, you are fast, I was editting my answer

If someone inserts 0 there is a check at line 35
Speed? It's all practice, practice

But don't tell Jessica what the check at line 35 actually does
Albareto McKenzie
Ranch Hand

Joined: Apr 08, 2009
Posts: 298
She will find it soon
 
Consider Paul's rocket mass heater.
 
subject: Homework help please!!