Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Minor if/else issue
import java.util.Scanner;
public class ShippingCost {
private static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
int shippingType;
double shippingCost, productCost, totalCost;
System.out.println("Shipping Costs");
System.out.print("Enter the cost of the product ordered: ");
productCost = input.nextDouble();
System.out.println("Standard shipping (enter 1) for $7.95");
System.out.println("Express shipping (enter 2) for $13.95");
System.out.println("Priority shipping (enter 3)for $23.95");
System.out.print("Enter your choice (1, 2 or 3):");
shippingType = input.nextInt();
if (shippingType == 1) {
shippingCost = 7.95;
} else if (shippingType == 2) {
shippingCost = 13.95;
} else {
shippingCost = 23.95;
}
totalCost = shippingCost + productCost;
System.out.println("The costs of the product is" + productCost + "plus shipping equals" + totalCost);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment