-7
我找不出爲什麼第二種方法不能執行。它編譯並接受輸入,但之後沒有任何反應。有人能指引我朝着正確的方向嗎?Java第二種靜態方法沒有執行
import javax.swing.JOptionPane;
public class Test1 {
public static void main(String[] arg) {
String hoursOfWorkString, costOfMaterialsString, nameOfProductString;
nameOfProductString = JOptionPane.showInputDialog(null, "Enter the name of the product. ", JOptionPane.QUESTION_MESSAGE);
hoursOfWorkString = JOptionPane.showInputDialog(null, "Enter the number of hours worked. ", JOptionPane.QUESTION_MESSAGE);
double hoursOfWork = Double.parseDouble(hoursOfWorkString);
costOfMaterialsString = JOptionPane.showInputDialog(null, "Enter the cost of the product. ", JOptionPane.QUESTION_MESSAGE);
double costOfMaterials = Double.parseDouble(costOfMaterialsString);
}
public static void CalulatePrice(double costOfMaterials, double hoursOfWork, String nameOfProductString) {
double salePercentage = 0.75, shipping = 6, markup = 14, retailPrice;
retailPrice = salePercentage * (costOfMaterials + (markup * hoursOfWork)) + shipping;
JOptionPane.showMessageDialog(null, String.format("The retaill price of the %. product is $ %.02f.", nameOfProductString, retailPrice));
}
}
更新:我使用了該示例並修復了一些其他錯誤,並運行它。看完評論後,我認爲它不會起作用。我只知道我的代碼裏有些東西是關閉的。
謝謝大家的意見。
這可能是因爲你不叫它? – Li357
我很想知道你爲什麼認爲它會執行。 – Andreas