这是一个已经工作了一段时间的作业问题,但我似乎无法弄清楚其余部分。
你的程序将计算一些咖啡袋的价格。 你会先询问用户;他们想要多少袋咖啡。
每袋的价格是每个5.50美元。你的价格还必须包括 装运这批货物需要多少箱子。有 提供三种尺寸的运输箱。一个大盒子可容纳20个袋子,一个 中型箱可容纳10个袋子,一个小盒子最多可容纳5个袋子。您 不能运送不满的大中型箱子。 (但小的 可以有1-5个袋子)每箱的运费价格很大= 1.80美元,中等= 1.00美元,小= 0.60美元。一个最终的价格变化是 可能的折扣。使用下面的图表来计算 咖啡价格的折扣(不包括运费)。0-24 bags - no discount 25-49 bags – 5% discount 50-99 bags – 10% discount 100-149 bags – 15% discount 150-199 bags - 20% discount 200-299 bags - 25% discount 300 and up - 30% discount
不在盒子上使用折扣。使用if语句或a 切换语句来完成这项工作。
import java.util.Scanner;
public class discount {
public static void main(String[] args) {
Scanner key = new Scanner(System.in);
System.out.println("Hello how are you? How many numberbags of coffee would you like?");
double numberbag;
double bag = 5.50;
numberbag = key.nextDouble();
System.out.println("Number of numberbags ordered: " + numberbag);
double price = (numberbag * bag);
System.out.println("- $" + price);
if (numberbag < 24 && numberbag > 0) {
System.out.println("no discount: $" + price);
}
else if (numberbag < 49 && numberbag > 25) {
System.out.println("5% discount: $" + price * .05);
}
else if (numberbag < 99 && numberbag > 50) {
System.out.println("10% discount: $" + price * .10);
}
else if (numberbag < 149 && numberbag > 100) {
System.out.println("15% discount: $" + price * .15);
}
else if (numberbag < 199 && numberbag > 150) {
System.out.println("20% discount: $" + price * .20);
}
else if (numberbag < 299 && numberbag > 200) {
System.out.println("25% discount: $" + price * .25);
}
else {
System.out.println("30% discount: $" + price * .30);
}
double small = ;
double medium = 10;
double large = 20;
double sp = 0.60;
double mp = 1.00;
double lp = 1.80;
double Rl = numberbag%large;
double Rm = Rl%medium;
double Rs = Rm%small;
答案 0 :(得分:0)
将其更改为此
if (numberbag < 24 && numberbag > 0) {
System.out.println("no discount: $" + price);
}
else if (numberbag < 49 && numberbag > 25) {
System.out.println("5% discount: $" + (price - (price * .05)));
}
else if (numberbag < 99 && numberbag > 50) {
System.out.println("10% discount: $" + (price - (price * .10)));
}
else if (numberbag < 149 && numberbag > 100) {
System.out.println("15% discount: $" + (price - (price * .15)));
}
else if (numberbag < 199 && numberbag > 150) {
System.out.println("20% discount: $" + (price - (price * .20)));
}
else if (numberbag < 299 && numberbag > 200) {
System.out.println("25% discount: $" + (price - (price * .25)));
}
else {
System.out.println("30% discount: $" + (price - (price * .30)));
}
答案 1 :(得分:0)
回答你关于盒子的第二个问题。 创建一个像这样的方法
public static double calculateBoxes(int y) {
int remainder = y%20;
int bigBox = y/20;
int remainder2 = remainder%10;
int medBox = remainder/10;
int remainder3 = remainder2%5;
int smallBox = remainder2/5;
if (remainder3 == 0){
}
else{
smallBox++;
}
double boxPrice = (bigBox*1.80)+(medBox*1.00)+(smallBox*.60);
return boxPrice;
}
然后像你这样从你的主人那里打电话
calculateBoxes(numberBag)