Studying for an exam and have a problem,I am a beginner. Its a discount calculator. Bag of coffee costs €3.75 10 bags or more 5% discount 20 bags or more 10% discount
What I have so far
import java.util.Scanner;
public class discount {
public static void main (String[] args){
//Scanner input; Keep this as one line. It is good practice
Scanner input = new Scanner(System.in);
double bag;
double discount;
double cost = 3.75;
//Input = new Scanner(System.ini); combined with line above.
System.out.println("Enter Numer of bag");
bag = input.nextDouble();
//If (bag ==>10&&<20) × .05 incorrect Java syntax
if(bag >= 10 && < 20) {
discount = 0.05;
}
else if(bag >= 20) {
discount = 0.10;
}
else {
discount = 0;
}
double finalPrice;
finalPrice = (cost * bag) * (1 - discount);
System.out.println("You ordered " + bag + " bags of coffee.");
System.out.println("Your dicount is " + discount + "%");
System.out.println("You total is: " + finalPrice);
} }
if(bag >= 10 && < 20)
to
if(bag >= 10 && bag < 20)
An easy mistake for a beginner! I kinda agree with the lecturer re the editor vs ide while learning the basics. You need to learn to read what the compiler tells you is wrong. And once you know the problem, I think you will agree, the syntax error message above gives a good indication of what is wrong.