package jp.co.bbreak.sokusen._2._1;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
public class PrintReceipt3{
public static void main(String[] args){
//明細データの作成
Detail detail1 = new Detail();
detail1.setItemName("お米5kg");
detail1.setAmount(new BigDecimal(1980));
Detail detail2 = new Detail();
detail2.setItemName("柿9個");
detail2.setAmount(new BigDecimal(398));
List<Detail> detailList = new ArrayList<>(); detailList.add(detail1); detailList.add(detail2); //明細行フォーマット文字の定義 String lineBase = "%-10s%10s円";// フォーマット文字を修正 //金額表示用のフォーマット定義 DecimalFormat df = new DecimalFormat("###,##0"); // 追加 //金額を表示用に加工 String dispAmount1 = df.format(detail1.getAmount().longValue()); String dispAmount2 = df.format(detail2.getAmount().longValue()); String result1 = String.format(lineBase, detail1.getItemName(),dispAmount1); // 変換した金額を表示するように修正 String result2 = String.format(lineBase, detail2.getItemName(),dispAmount2); //明細の出力 System.out.println(result1); System.out.println(result2);
}
}
これを実行するとコンソールに以下のエラーが表示されます。
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
'<>' オペレーターは 1.7 より下のソース・レベルで許可されていません
メソッド longValue() は型 Object で未定義です
メソッド longValue() は型 Object で未定義です
at jp.co.bbreak.sokusen._2._ka1.PrintReceipt3.main(PrintReceipt3.java:19)
このエラーの解決方法を教えていただきたいです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。