Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2011
    Posts
    1
    Rep Power
    0

    Post 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.

  2. #2
    DiamondSoul is offline Member
    Join Date
    Oct 2011
    Posts
    83
    Rep Power
    0

    Default 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:
    Java Code:
    sum = sum + weeklypayment;
    and move it inside the for loop.

Similar Threads

  1. Final int
    By Fireking in forum New To Java
    Replies: 12
    Last Post: 06-22-2013, 05:44 PM
  2. Replies: 4
    Last Post: 06-11-2013, 01:37 AM
  3. [SOLVED] is final class members are also final ?
    By haoberoi in forum New To Java
    Replies: 4
    Last Post: 11-10-2008, 03:01 PM
  4. Scala 2.5.1-final
    By Jamie in forum Java Software
    Replies: 0
    Last Post: 06-14-2007, 03:09 PM
  5. Poi 3.0-final
    By levent in forum Java Software
    Replies: 0
    Last Post: 05-22-2007, 07:05 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •