【发布时间】:2013-07-02 01:01:13
【问题描述】:
我正在练习出书,自学。 这让我大吃一惊。如果有人可以帮助我?
第一个、第二个和第三个袋子的金额如何减去并收取总和 包数?
项目要求这些标准 > 作业详情 该公司只出售 2 磅袋装的咖啡。 每个袋子的价格是 5.50。 当客户下订单时,他们会用盒子运送咖啡。 这些盒子有三种尺寸。大号(20袋,中号(10袋),小号(5袋)。
一个大盒子的成本是 1.80 美元 中等 $1.00 小 $0.60 例如,订单以最便宜的方式发货。 包装的内容是把大中型箱子完全装满。也就是说,盒子已经装满了。只有小盒子可以有空格。但这不会让第三个盒子完全装满。开发一个计算订单总成本的程序。显示如下格式:
订购的行李数量:52 - 286.00 美元
使用的盒子 2 大 - 3.60 1 中等 - 1.00 1 小 - 0.60
您的总费用为:291.20 美元
示例代码
import javax.swing.*;
import java.lang.*;
import java.text.DecimalFormat;
import java.util.*;
import java.io.*;
import java.math.*;
public class CoffeeBags {
public static void main(String [] args) throws IOException
{
DecimalFormat df = new DecimalFormat ("#,##0.00");
BufferedReader bufReader = new BufferedReader(new InputStreamReader(System.in));
int numberOfBags;
int largeBags = 2;
int mediumBags = 1;
int smallBags = 1;
double costOfLargeBags = 3.60;
double costOfMediumBags = 1.00;
double costOfSmallBags = 0.60;
double costPerBag = 5.50;
double totalCost;
double totalCostWithBags;
System.out.print("Enter number of bags to order: ");
String numberOfBagsStr = bufReader.readLine();
numberOfBags = Integer.parseInt(numberOfBagsStr);
totalCost = numberOfBags * costPerBag;
System.out.println("Number of bags ordered: " + numberOfBags + " - $" + df.format(totalCost));
System.out.println("Boxes used:");
System.out.println(" " + largeBags + " Large - $" + df.format(costOfLargeBags));
System.out.println(" " + mediumBags + " Medium - $" + df.format(costOfMediumBags));
System.out.println(" " + smallBags + " Small - $" + df.format(costOfSmallBags));
//System.out.print("Your total cost is: $ " + (totalCostWithBags));
//String numberOfUnitsStr = bufReader.readLine();
//numberOfUnits = Integer.parseInt(numberOfUnitsStr);
System.out.println("\nPress any key to continue. . .");
System.exit(0);
}
}
【问题讨论】:
标签: java integer-division