Me very new programmer, I'm making a simple vending machine program, and so far I have two items. I setup a scanner that takes user input and if statements that evaluate to true if a user enters a specific input. When I enter "A" for example it prints both if statements when it should only print one.
Here is my code so far:
import java.util.Scanner;
public class Testing {
public static void main(String args[]) {
Scanner scnr = new Scanner(System.in);
double milkPrice = 2.00;
double sodaPrice = 2.25;
System.out.println("Please make a selection:");
String userResponse = scnr.next();
//If user input is A or a
if (userResponse.equals("A") ||
userResponse.equals("a"))
{
System.out.printf("%s", "You have bought Milk for "); System.out.printf("%1.2f %n", milkPrice);
}
System.out.println("Please make a selection:");
//If user input is B or b
if (userResponse.equals("B") ||
userResponse.equals("b"));
{
System.out.printf("%s", "You have bought Soda for "); System.out.printf("%1.2f %n", sodaPrice);
}
scnr.close();
}
}