Results 1 to 2 of 2
- 10-19-2011, 04:23 AM #1
Member
- Join Date
- Oct 2011
- Posts
- 1
- Rep Power
- 0
what am i doing wrong? I don't know what my final sum should be.
import java.util.Scanner;
import java.text.DecimalFormat;
public class Burger
{
static Scanner console = new Scanner (System.in);
public static void main (String [] args)
{
double sum = 0;
for (int week = 1; week <= 4; week = week+1)
{
System.out.print("How many hours did you work in week " + week + "? ");
int h = console.nextInt();
DecimalFormat d = new DecimalFormat ("0.00");
double weeklypayment = (h*5.15) - (h * 5.15 * 0.3);
System.out.println("Your take-home pay is $" + d.format(weeklypayment));
}
System.out.println();
sum = sum + weeklypayment;
DecimalFormat d = new DecimalFormat ("0.00");
System.out.println("Your total pay for the month is $" + d.format(sum));
System.out.println ("Hope you enjoy working at Babbage Burgers.");
}
}Last edited by amyissmartical; 10-19-2011 at 04:41 AM.
- 10-19-2011, 09:04 PM #2
Member
- Join Date
- Oct 2011
- Posts
- 83
- Rep Power
- 0
Re: what am i doing wrong? I don't know what my final sum should be.
For future reference, please use [code] tags when posting source code - makes it much more readable.
Your problem is that you need to add the weekly payment inside the for loop, so it adds all four weekly payments. Take this line of code:
and move it inside the for loop.Java Code:sum = sum + weeklypayment;
Similar Threads
-
Wrong output (well.. the one who's wrong is probably me ;) )
By shacht1 in forum New To JavaReplies: 2Last Post: 11-22-2009, 03:48 PM -
[SOLVED] is final class members are also final ?
By haoberoi in forum New To JavaReplies: 4Last Post: 11-10-2008, 03:01 PM -
Final int
By Fireking in forum New To JavaReplies: 10Last Post: 09-05-2008, 07:12 AM -
Scala 2.5.1-final
By Jamie in forum Java SoftwareReplies: 0Last Post: 06-14-2007, 03:09 PM -
Poi 3.0-final
By levent in forum Java SoftwareReplies: 0Last Post: 05-22-2007, 07:05 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks