Answer:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
double cost = 0;
double priceF, priceS, priceT;
int nOne = 0, nTwo = 0, nThree = 0;
int fBurn, sBurn, tBurn;
int burnTime = 0;
isEnd = "n";
while (isEnd == "n"){
Scanner in = new Scanner(System.in);
int option = in.nextInt();
if (option == 1){
priceF = 2.50;
fBurn = 5;
System.out.print("Enter number of items: ");
nOne += in.nextInt();
burnTime += fBurn * nOne;
cost += priceF * nOne;
} else if (option== 2){
priceS = 3.75;
sBurn = 7;
System.out.print("Enter number of items: ");
nTwo += in.nextInt();
burnTime += sBurn * nTwo;
cost += priceS * nTwo;
} else if(option == 3){
priceT = 5.99;
tBurn = 12;
System.out.print("Enter number of items: ");
nThree += in.nextInt();
burnTime += tBurn * nThree ;
cost += priceT * nThree;
} else{
System.out.println("option must be between 1 and 3");
}
System.out.print("Do you want to end the order? y/n: ");
isEnd = in.nextLine();
}
System.out.println("Number of Type 1 candles bought : "+nOne);
System.out.println("Number of Type 2 candles bought : "+nTwo);
System.out.println("Number of Type 3 candles bought : "+nThree);
System.out.println("Total cost is : "+cost);
System.out.println("Total burn time is : "+burnTime);
double cpm = (burnTime * 60) / cost;
System.out.println("Cost per minute : "+cpm);
}
}
Explanation:
The Java program prompts the user to continuously choose from three options 1, 2 and 3. The prices, the burn time and the cost per minute burn of the total candles ordered are printed out.