初心者として我慢してください、
コードは抽出です:
'CalcCost calculate = new CalcCost(); '
String key = stockNofive.getText();
String quantityTxt = quantityfive.getText();
int QuantityInt = Integer.parseInt(quantityTxt);
calculate.String(key, quantityTxt); // sending key and quantity to another class for user input check
calculate.Jlabel(stockJLBfive, quantityJLBfive); // sending jlabel for colour change if any error found
error.Colour();// recieve error value if any, if there is do not carry on,
//if error passes then do the following
calculate.setKey(key);
calculate.setQuantity(QuantityInt);
double cost = calculate.calculateBill();
information.append("\n\nTotal cost: £" + pounds.format(cost));
............
........
これはエラーチェッククラスです
try {
if (key.equals("")) {
StockJLb.setText("<html><span style=\"color: red;\">Enter stock number</span></html>");
JOptionPane.showMessageDialog(null, "One or more fields missing");
return StockJLb;
}
if (QuantityStr.equals("")) {
QuantityJLb.setText("<html><span style=\"color: red;\">Enter quantity</span></html>");
JOptionPane.showMessageDialog(null, "One or more fields blank");
return QuantityJLb;
}
} catch (NumberFormatException nfe) {
QuantityJLb.setText("<html><span style=\"color: red;\">Enter quantity</span></html>");
JOptionPane.showMessageDialog(null, "'" + QuantityStr + "' is not a number");
error= true;
return QuantityJLb;
}
さらにコードが必要な場合、または他の何かが必要な場合は、今すぐ2週間これに固執してください。それでも不明な場合は、コードにメモを入れてください。エラーが発生した場合は計算を続行しないでください。エラーがない場合はエラーチェックに合格し、計算を実行します。ステートメントの場合は試行します。ブール値を追加しようとしましたが、それでも理解できません。