So I have this question homework that I'm stuck on,
"Online Book Merchants offers premium customers 1 free book with every purchase of 5 or more books and offers 2 free books with every purchase of 8 or more books. It offers regular customers 1 free book with every purchase of 7 or more books, and offers 2 free books with every purchase of 12 or more books. Create a java program that demonstrates this store" I was told I need to use the nested if, so my code looks like this now:
Scanner input = new Scanner (System.in);
System.out.println("Hello user, enter your status customer (Regular/Premium).");
String status = input.next();
if ("premium".equalsIgnoreCase(status)) {
System.out.println("Enter amount of books purchased");
int preBooks = input.nextInt();
if (preBooks >=5) {
System.out.println("Congratulations Premium user, you have earned 1 free book.");
}
else if (preBooks >=8) {
System.out.println("Congratulations Premium user, you have earned 2 free books.");
}
}
else if ("Regular".equalsIgnoreCase(status)) {
System.out.println("Enter amount of books purchased user.");
int regBooks = input.nextInt();
if (regBooks >=7) {
System.out.println("Congratulations Regular user, you have earned 1 free book.");
}
else if (regBooks >=12) {
System.out.println("Congratulations Regular user, you have earned 2 free books.");
}
}
else {
System.out.println("Wrong input.");
}
And so far at least to the output, it is correct my only issue is when I type premium then lets say 8, it would still give me only 1 books (which is for the 5)
and likewise situation for Regular
I do not know what to do or what is wrong with my code so if anyone could help I would really appreciate it :/
Aucun commentaire:
Enregistrer un commentaire