Here's a snippet of my code for an assignment. I can't seem to get the boolean flag to work properly. When i try to figure it out, either every name gets the discount or no name gets the discount. To clarify the name Mike or Diana should give a discount.
String firstName; //user's first name
boolean discount = false; //flag, true if user is eligible for discount
int inches; //size of the pizza
char crustType; //code for type of crust
String crust; //name of crust
double cost = 12.99; //cost of the pizza
final double TAX_RATE = .08; //sales tax rate
double tax; //amount of tax
char choice; //user's choice
String input; //user input
String toppings = "Cheese "; //list of toppings
int numberOfToppings = 0; //number of toppings
//prompt user and get first name
System.out.println("Welcome to Mike and Diane's Pizza");
System.out.print("Enter your first name: ");
firstName = keyboard.nextLine();
if (firstName == "mike" || firstName == "diana" || firstName == "Mike" || firstName == "Diana" ||
firstName == "MIKE" || firstName == "DIANA")
{
discount = true;
}
if (discount = true)
{
cost -= 2.0;
System.out.println ("You are eligible for a $2 discount.");