I've been working on a solution of a problem in Java. I have a store and I need to ask the customer if she/he had bought anything. If he/she types "yes" I want the program to continue to the next question and if he/she types "no" I want a message to appears such as "have a nice day!" and then I want the program to stop. How can I manage this?
Thank you!
Here's what I've done so far ~Line 17 to 20~ (but it doesn't work very well):
import java.util.Scanner;
public class Discount {
public static void main(String[] args) {
String cname;
float I_price, drate, discount, dprice;
Scanner in = new Scanner(System.in);
System.out.println("Enter Costumers Name:");
cname = in.next();
System.out.println("Have you bought anything?");
if (cname == "no") {
System.out.println("Have a good day!");
System.exit(0);
}
System.out.println("Enter Price of Item:");
I_price = in.nextFloat();
System.out.println("Enter Discount Rate:");
drate = in.nextFloat();
discount = (I_price * drate / 100);
dprice = (I_price - discount);
System.out.println(
"Costumer Name:" + cname + "\n" + "Discount Rate:" + discount + "\n" + "Discounted Price:" + dprice + "\n");
}
}