Last active
March 30, 2019 17:43
-
-
Save donhamiltoniii/94d5e32a39e341c547f74e6297a03de5 to your computer and use it in GitHub Desktop.
Minor if/else issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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