so i have these two classes called shipment and insurance, one calculates the price for shipping and the other adds the insurance. The shipment logic is working just fine but for some reason the if statements in Insurance class is not working i dont know whats going on. The output for the Insurance cost is always 2.45. why does it do this?
Shipment class:
package theshipment; public class Shipment extends Main { protected double weight = Double.parseDouble(savedArgs[1]); protected double shippingCost; protected double methodCost; protected String method = savedArgs[2]; public void calculateShippingCost(){ if (weight<=10||weight>=1){ if (method.equalsIgnoreCase("T")) methodCost = weight * 3.00; else if (method.equalsIgnoreCase("A")) methodCost = weight * 4.00; else if (method.equalsIgnoreCase("M")) methodCost = weight * 2.00; else{} }else if (weight<=20||weight>=10.1){ if (method.equalsIgnoreCase("T")) methodCost = weight * 2.45; else if (method.equalsIgnoreCase("A")) methodCost = weight * 3.00; else if (method.equalsIgnoreCase("M")) methodCost = weight * 1.75; else{} }else if (weight>20){ if (method.equalsIgnoreCase("T")) methodCost = weight * 1.95; else if (method.equalsIgnoreCase("A")) methodCost = weight * 2.50; else if (method.equalsIgnoreCase("M")) methodCost = weight * 1.55; else{} }else{} } } And the insurance class:
package theshipment; public class Insurance extends Shipment{ private void calculateInsurance(){ if (methodCost<=10.0||methodCost>=0.0) shippingCost = methodCost + 2.45; else if(methodCost<=30.0||methodCost>=10.1) shippingCost = methodCost + 3.95; else if(methodCost>=30.01) shippingCost = methodCost + 5.55; else{} } public void run(){ calculateShippingCost(); calculateInsurance(); } public String displayOrder(){ return ("Method cost: " + methodCost + " " + "Insurance cost: " + (shippingCost-methodCost) + " Total shipping cost: " + shippingCost); } }