捆绑以解决显示运输成本的问题,其中一个包裹比另一个包裹更贵(Java)



我目前正在进行一项任务,该任务从用户的长度、高度、宽度中获取输入值,并使用一种助手方法来计算体积<1是3美元,每增加一个数量,成本就会增加1美元。
代码将显示两个包裹的运输成本,并输出两个运输成本之间的差额。

我陷入困境的地方是我相信我困惑自己的地方是的要求之一

i。如果没有差异,显示成本是相同的。

ii。如果其中一个的成本低于另一个的两倍,则显示它"略高于

iii."如果其中一个的成本低于另一个的三倍,则显示为"两倍">

iv。如果其中一个的成本低于另一个的四倍,则显示为"三重">

v。如果其中一个的成本低于另一个的五倍,则显示它是"四倍">

vi。否则,显示为计算的多重

public class Shipment {
private Package pack1, pack2;
private String message;
private NumberFormat currency = NumberFormat.getCurrencyInstance();
private DecimalFormat decimal = new DecimalFormat("#.##");
public Shipment() {
System.out.println("Welcome to Jaylen Carroll's shipping calculator!!");
this.pack1 = new Package();
this.pack2 = new Package();
message = "";
}// prints the title uses default constructor and 
public void inputPackages() {
System.out.println("Enter first package dimensions");
inputPackage(this.pack1);
System.out.println();
System.out.println("Enter second package dimensions");
inputPackage(this.pack2);
}
public void inputPackage(Package pack) {
pack.inputLength();
pack.inputWidth();
pack.inputHeight();
}
public void calculateCost() {
double volP1 = pack1.calcVolume();
double volP2 = pack2.calcVolume();
double costPack1 = 3+(volP1-1);
double costPack2 = 3+(volP2-1);
System.out.println("Package 1 will cost "+costPack1);
System.out.println("Package 2 will cost "+costPack2);
if(volP1 == volP2) {
System.out.println("The shipping costs are the same.");
/* How can I get this if statement to print the cost difference and display which one is more expensive than the other.*/
}
public void display() {
System.out.print("First package dimensions: ");
this.pack1.displayDimensions();
//add memo about shipping

System.out.print("Second package dimensions: ");
this.pack2.displayDimensions();
//add memo about shipping 
}

}

你看到的是这样的东西吗?

if(volP1 == volP2) {
System.out.println("The shipping costs are the same.");
}else if(volP1 < (2*volP2)){
double result = volP2 - volP1;
System.out.println("Package one is " +result +" cheaper than package two");
}

最新更新