Results 1 to 4 of 4
  1. #1
    icykum is offline Member
    Join Date
    Sep 2012
    Posts
    5
    Rep Power
    0

    Default What is wrong with my program?

    import javax.swing.*;
    import java.util.*;
    import java.text.*;

    class Box {

    //Data Members
    private static final double BAGPRICE= 5.50;
    private static final double LRGPRICE= 1.80;
    private static final double MEDPRICE= 1.00;
    private static final double SMLPRICE= 0.60;
    private String BagAmount;
    private int BagAmount1;
    private double bagPrice, Boxes, LBag1, MBag1, SBag1, SmlPrice, MedPrice, LrgPrice;

    //Number of bags
    public int NumberOfBags ( ) {
    String BagAmount=JOptionPane.showInputDialog("Enter number of boxes ordered.");
    int BagAmount1=Integer.parseInt(BagAmount);
    return BagAmount1;
    }

    //Price of Ordered Bags (not total)
    public double getBagPrice ( ) {
    bagPrice=BagAmount1*5.50;
    return bagPrice;
    }

    //Amount of Large Bags and Price
    public double NumberOfLrgBags ( ) {
    double Boxes=(double) BagAmount1;
    double LBag=Boxes/20;
    double LBag1=((int)LBag)*20;
    return LBag1;
    }
    public double LrgBagPrice ( ) {
    double LrgPrice=LBag1*LRGPRICE;
    return LrgPrice;
    }

    //Amount of Medium Bags and Price
    public double NumberOfMedBags ( ) {
    double MBag=(Boxes-LBag1)/10;
    double MBag1=((int)MBag)*10;
    return MBag1;
    }
    public double MedBagPrice ( ) {
    double MedPrice=MBag1*MEDPRICE;
    return MedPrice;
    }

    //Amount of Small Bags and Price
    public double NumberOfSmlBags ( ) {
    double SBag=(Boxes-LBag1-MBag1)/5;
    double SBag1= Math.ceil(SBag);
    return SBag1;
    }
    public double SmlBagPrice ( ) {
    double SmlPrice=SBag1*SMLPRICE;
    return SmlPrice;
    }
    //Total price
    public double TotalPrice ( ) {
    double totalPrice=SmlPrice+MedPrice+LrgPrice+bagPrice;
    return totalPrice;
    }
    }

    class OrderReceipt {
    public static void main (String [] args){
    DecimalFormat df=new DecimalFormat ("0.00");
    Box Yum;
    Yum=new Box();

    System.out.println(Yum.NumberOfBags());
    System.out.println(Yum.getBagPrice());
    }
    }



    The output is
    52
    0.0

    Rather than
    52
    286.00
    Last edited by icykum; 09-23-2012 at 07:32 PM.

  2. #2
    JavaAdviser is offline Member
    Join Date
    Sep 2012
    Posts
    26
    Rep Power
    0

    Default Re: What is wrong with my program?

    Check if all variable declared have been initialized at some point.

    It would also be nice if you
    1. Follow the forum rules.
    2. Post only the code you think is responsible for the error.
    3. Say what you are trying to do or what your assignment is.
    Last edited by JavaAdviser; 09-23-2012 at 07:48 PM.

  3. #3
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default Re: What is wrong with my program?

    What makes you think that something is wrong with your program?
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default Re: What is wrong with my program?

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. What's wrong with this program?
    By java_aim in forum New To Java
    Replies: 8
    Last Post: 11-02-2011, 01:01 PM
  2. What is wrong with this program!?
    By flecdorbee in forum New To Java
    Replies: 5
    Last Post: 02-26-2011, 01:11 AM
  3. what the wrong in my program ><
    By MSs.Java in forum New To Java
    Replies: 4
    Last Post: 05-03-2010, 01:28 PM
  4. What's wrong in my program...?
    By Annatar in forum Java Software
    Replies: 3
    Last Post: 10-31-2008, 06:03 AM
  5. what is wrong with this program ?
    By Poor Bee in forum New To Java
    Replies: 1
    Last Post: 05-07-2008, 07:23 PM

Posting Permissions

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