Results 1 to 4 of 4
Thread: What is wrong with my program?
- 09-23-2012, 07:29 PM #1
Member
- Join Date
- Sep 2012
- Posts
- 5
- Rep Power
- 0
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.00Last edited by icykum; 09-23-2012 at 07:32 PM.
- 09-23-2012, 07:39 PM #2
Member
- Join Date
- Sep 2012
- Posts
- 26
- Rep Power
- 0
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
- Follow the forum rules.
- Post only the code you think is responsible for the error.
- Say what you are trying to do or what your assignment is.
Last edited by JavaAdviser; 09-23-2012 at 07:48 PM.
- 09-23-2012, 09:44 PM #3
Student
- Join Date
- Jul 2012
- Location
- United States
- Posts
- 328
- Rep Power
- 1
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
- 09-23-2012, 10:34 PM #4
Re: What is wrong with my program?
Forum Rules -- particularly the third paragraph
Guide For New Members
BB Code List - Java Programming Forum
dbWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
What's wrong with this program?
By java_aim in forum New To JavaReplies: 8Last Post: 11-02-2011, 01:01 PM -
What is wrong with this program!?
By flecdorbee in forum New To JavaReplies: 5Last Post: 02-26-2011, 01:11 AM -
what the wrong in my program ><
By MSs.Java in forum New To JavaReplies: 4Last Post: 05-03-2010, 01:28 PM -
What's wrong in my program...?
By Annatar in forum Java SoftwareReplies: 3Last Post: 10-31-2008, 06:03 AM -
what is wrong with this program ?
By Poor Bee in forum New To JavaReplies: 1Last Post: 05-07-2008, 07:23 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks