2017-02-06 12 views
-1

最後のJOptionPaneで "文字列をコンポーネントに変換できません" ひどい見た目のフォーマットに対するご迷惑をおかけします。私はスイッチを使用することがはるかに簡単であることを知っている、これは私のJavaクラスの割り当てです。すべての提案が歓迎されました。ありがとうJOptionPaneで "文字列をコンポーネントに変換できません"

import javax.swing.JOptionPane; 
import java.util.*; 
import java.text.*; 
import java.lang.String; 

public class Project4A 
{ 
    public static void main(String[] args) 
    { 
     NumberFormat formatter = NumberFormat.getCurrencyInstance(); 
     Scanner sc = new Scanner(System.in); 
     double dcostBagel = 2.00; //Variables 
     double dcostDonut = 1.50; 
     double dcostCrois = 3.00; 
     double dcostLatte = 1.50; 
     double dcostCoffee = 1.25; 
     double dcostMilk = 1.00; 
     double dcostTea = 0.50; 
     double dfoodChoiceCost; 
     double dbevChoiceCost; 
     double dtotDue; 
     double dtotCost; 
     int ichoiceFood; 
     int ichoiceBev; 
     int inumOrdered; 
     String choiceFood; 
     String choiceBev; 
     String finChoiceFood; 
     String finChoiceBev; 
     //Prompts 
     choiceFood = JOptionPane.showInputDialog("Welcome to BeBe's Best BreakfastnChoose a Breakfast Item:n1: Bagel @ "+formatter.format(dcostBagel) + "n2: Donut @ "+formatter.format(dcostDonut) + "n3: Croissant @ "+formatter.format(dcostCrois)); 
     ichoiceFood = Integer.parseInt(choiceFood); 
     choiceBev = JOptionPane.showInputDialog("Choose one of the following beverages:nEnter:n1: Latte @ "+formatter.format(dcostLatte)+"n2: Coffee @ "+formatter.format(dcostCoffee)+"n3: Milk @ "+formatter.format(dcostMilk)+"n4: Tea @ "+formatter.format(dcostTea)); 
     ichoiceBev = Integer.parseInt(choiceBev); 
     //If Elses for Food 
     if(ichoiceFood == 1) 
     { 
      finChoiceFood = "Bagel"; 
      dfoodChoiceCost = dcostBagel; 
     } 
     else if(ichoiceFood == 2) 
     { 
      finChoiceFood = "Donut"; 
      dfoodChoiceCost = dcostDonut; 
     } 
     else 
     { 
      finChoiceFood = "Croissant"; 
      dfoodChoiceCost = dcostCrois; 
     } 
     //If Elses for Beverages 
     if(ichoiceBev == 1) 
     { 
      finChoiceBev = "Latte"; 
      dbevChoiceCost = dcostLatte; 
     } 
     else if(ichoiceBev == 2) 
     { 
      finChoiceBev = "Coffee"; 
      dbevChoiceCost = dcostCoffee; 
     } 
     else if(ichoiceBev == 3) 
     { 
      finChoiceBev = "Milk"; 
      dbevChoiceCost = dcostMilk; 
     } 
     else 
     { 
      finChoiceBev = "Tea"; 
      dbevChoiceCost = dcostTea; 
     } 
     /
     //Retreive num ordered 
     System.out.println("How many items would you like?(1 to 20"); 
     inumOrdered = sc.nextInt(); 
     //Calculations 
     dtotCost = dbevChoiceCost + dfoodChoiceCost; 
     dtotDue = dtotCost * inumOrdered; 
     //Integer.toString(inumOrdered); 
     //Final Output 
     JOptionPane.showMessageDialog("Breakfast ordered:n"+finChoiceFood+" @ "+formatter.format(dfoodChoiceCost)+"nnBeverage ordered:n"+finChoiceBev+" @ "+formatter.format(dbevChoiceCost)+"nnTotal cost: "+formatter.format(dtotCost)+"nNumber ordered: "+inumOrdered,"Your Bill"); 
    } 
} 

答えて

0

コードがshowMethodDialogue(...)機能(複数可)の任意のメソッドのシグネチャが一致しないれます。 JOptionPaneJavadocを見てみましょう:

static void showMessageDialog(Component parentComponent, Object message): "Message" というタイトルの情報メッセージダイアログを表示します。

static void showMessageDialog(Component parentComponent, Object message, String title, int messageType):メッセージタイプ で指定されたデフォルトアイコンを使用して にメッセージが表示されるというダイアログが表示されます。

static void showMessageDialog(Component parentComponent, Object message, String title, int messageType, Icon icon):すべてのパラメータを指定してメッセージを表示するダイアログが表示されます。

parentComponentは、「ダイアログが表示されるフレームを決定します; nullの場合、またはparentComponentにフレームがない場合、デフォルトのフレームが使用されます」と定義されています。

関連する問題