私がこれまでに持っているコードは次のとおりです。
public class Project4 {
public static void main (String[] args) throws IOException {
final double OUNCES_PER_POUND = 16.0;
double pricePerPound;
double weightOunces;
double weightPounds;
double totalPrice;
String itemName;
Scanner fileScan = new Scanner(new File(args[0]));
NumberFormat money = NumberFormat.getCurrencyInstance();
DecimalFormat fmt = new DecimalFormat("0.00");
// Missing code that reads variables from text file goes here
weightPounds = weightOunces / OUNCES_PER_POUND;
totalPrice = weightPounds * pricePerPound;
System.out.println("Item: " + itemName);
System.out.println("Unit Price: " + money.format(pricePerPound));
System.out.println("Weight: " + fmt.format(weightPounds) + " pounds");
System.out.println("TOTAL: " + money.format(totalPrice));
}
}
私がやろうとしているのは、テキスト ファイルから変数を取得する方法を理解することです。ファイルはコマンドラインで引数として宣言する必要があるため、ヘッダーがそのまま設定されます。テキスト ファイルは基本的に、必要な 3 つの変数で、それぞれが別の行にあります。
テキストファイルの各行を独自の個別の変数として宣言できるように、変数を設定するために何をする必要があるかについて、誰かがヒントをくれたり、情報を教えてくれることを望んでいました。