我到目前为止的代码是:
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));
}
}
我想做的是弄清楚如何从文本文件中提取变量。该文件必须在命令行中声明为参数,这就是按原样设置标头的原因。文本文件基本上是我需要的三个变量,每个变量都在单独的行上。
我希望有人给我一个提示或指出我需要做什么来设置变量的一些信息,以便我可以将文本文件中的每一行声明为它自己的单独变量。