joptionpane으로 표시되는 총 비용과 해당 음료를 얻는 방법은 무엇입니까? BeBe 's Best Breakfast의 아침 식사 주문 시스템을 시뮬레이션 해 달라는 요청을 받았습니다. 나는 JOptionPane을 표시하여 사용자에게 아침 식사와 주문 음료 선택을 요구한다. 그런 다음 사무실에서 주문한 아침 식사 수 (1 - 5)에 대한 프롬프트를 제공하고 스캐너 개체를 사용하여 입력 내용을 읽으려고합니다. JOptionPane에 사용자의 Bill을 출력합니다.JOptionPane의 총 비용이 표시되지 않습니다.
import javax.swing.*;
import java.util.Scanner;
import java.text.*;
import java.util.Locale;
public class ProjectFourA
{
private static final float bagel = 2.00f, donut = 1.50f, croissant = 3.00f;
private static final float latte = 1.50f, coffee = 1.25f, milk = 1.00f, tea = 0.50f;
private float cost,extracost;
public static void main(String[]args)
{
Scanner breakfast = new Scanner(System.in);
NumberFormat mfmt = NumberFormat.getCurrencyInstance(Locale.US);
int size, choice, num;
String ch = JOptionPane.showInputDialog("Welcome to BeBe's Best Breakfast choose a breakfast item." + "\n1 to order Bagel"+"\n2 to order Donut"+"\n3 to order Croissant");
choice = Integer.parseInt(ch);
String nm = JOptionPane.showInputDialog("Choose one of the following beverages:" + "\n1 for Latte"+"\n2 for Coffee"+"\n3 for Milk"+"\n4 for Tea");
num = Integer.parseInt(nm);
float cost=0.0f, extracost=0.0f;
float price;
String str="", topstr="";
if (choice == 1)
{
cost = bagel;
str = "Bagel";
String inputStr = JOptionPane.showInputDialog(null, "Enter quantity: 1-5");
inputStr = breakfast.nextLine();
}
else if (choice == 2)
{
cost = donut;
str = "Donut";
String inputStr = JOptionPane.showInputDialog(null, "Enter quantity: 1-5");
inputStr = breakfast.nextLine();
}
else if (choice == 3)
{
cost = croissant;
str = "Croissant";
String inputStr = JOptionPane.showInputDialog(null, "Enter quantity: 1-5");
inputStr = breakfast.nextLine();
}
float totCost = extracost + cost;
JOptionPane.showMessageDialog(null,("Breakfast ordered:" +str + "\nBeverage ordered: "+topstr + "\nTotal cost: $"+totCost));
}
}
제거합니다. 들여 쓰기 스타일을 일정하고 일관성있게 사용하는 것을 포함하여 좋은 서식은 다른 사람들 (** us **!)이 귀하의 코드를 더 잘 이해할 수 있도록 도와 주며 더 중요한 것은 ** 당신 **이 귀하의 코드를 더 잘 이해하고 귀하의 자신의 버그. 또한 여기에 자원 봉사자들이 당신을 도울 수 있도록 노력하겠다는 것을 보여 주며 그 노력은 ** 많이 감사합니다 **. –