Skip to content

Instantly share code, notes, and snippets.

@donhamiltoniii
Last active March 30, 2019 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donhamiltoniii/94d5e32a39e341c547f74e6297a03de5 to your computer and use it in GitHub Desktop.
Save donhamiltoniii/94d5e32a39e341c547f74e6297a03de5 to your computer and use it in GitHub Desktop.
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