Hello,
I'm trying some basic Java exercises, but I'm stuck on one of them.
My code is:
import javax.swing.JOptionPane; public class PrintingDiscount { public static void main(String[] args) { String numberOfFlyersInput = JOptionPane.showInputDialog("How many flyers?"); String numberOfPostersInput = JOptionPane.showInputDialog("How many posters?"); int numberOfFlyers = Integer.parseInt(numberOfFlyersInput); int numberOfPosters = Integer.parseInt(numberOfPostersInput); double flyerTotal = 0; double posterTotal = 0; double grandTotal = 0; double costOfPoster = 2.00; /* if (numberOfFlyers >= 500) { double costOfFlyer = 0.005; } else { double costOfFlyer = 0.01; } */ flyerTotal = (costOfFlyer * numberOfFlyers); posterTotal = (costOfPoster * numberOfPosters); grandTotal = (flyerTotal + posterTotal); JOptionPane.showMessageDialog(null, "Your flyers will cost £" + flyerTotal + "\nYour posters will cost £" + posterTotal + "\nIn total, this will cost £" + grandTotal); } }
The part commented out is my problem. I basically want to declare costOfFlyer as 0.01, unless the number entered by the user (numberOfFlyers) is 500 or more, in which case I want it to be 0.005.
So, I've roughly coded what I thought might achieve this, but it is obviously incorrect since the compiler now cant find the variable costOfFlyer.
Any tips would be appreciated. Thanks