I have a couple of else/if statements in my code below. However I want to set a final variable that will set the final if statement depending on the users input. Lets say the user chooses to buy 6 "lathe". The discount applied will be lathecost * 0.10. I want to store that variable so I can use it in the future. However, I do not want to create a seperate variable if the user chooses 2 or 0. I want to the variable to know what the user chose and depending on what if/else statement itll store that. If the user chooses 2- itll store the final cost of lathecost * 0.05, if the user chooses 10 itll store the final cost of lathecost * 0.10, and so on. How can I achieve this?
double numlathe;
numlathe = input.nextFloat();
final double priceoflathe = 20000;
double lathecost = priceoflathe * numlathe;
if (numlathe<0) {
System.out.println("No discount applicable for 0 number of lathe purchase");
}
else if(numlathe<2) {
System.out.println("Discount of lathe matchine purchase = 0 ");
}
else if(numlathe<5){
System.out.println("There is discount that can be applied");
System.out.println("Total cost so far is" + lathecost * 0.05 + " dollars");
}
else if(numlathe>=5){
System.out.println("There is discount that can be applied.");
System.out.println("Total cost so far with discount is " + lathecost * 0.10 + " dollars");
}
Aucun commentaire:
Enregistrer un commentaire