【发布时间】:2017-02-11 17:11:43
【问题描述】:
我希望有人可以帮助我。
我正在尝试创建一个程序来从输入文件读取变量到输出文件 输入文件如下:员工的名字,两个双精度值,卖家的工资和他/她销售的总价值。
JOAO
450.00
1230.30
FDJSI
333.00
2.00
MAJDIIDFH
433.00
222.50
要求的卖家总工资为输出
这是我一直在尝试制作的代码
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
/**
* A simple example program that reads a text file line by line and display each line.
*/
public class Salary {
public static void main(String[] args) {
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader("temp.txt"));
String sellerName;
while ((sellerName = br.readLine()) != null) {
String salary = br.readLine();
String totalSale =br.readLine();
double percentage = 0.15;
double SaleAfterPercentage = totalSale * percentage;
//value of the total salary
double finalSalary = salary + SaleAfterPercentage ;
System.out.println(sellerName);
// System.out.println(salary);
// System.out.println(totalSale);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null) {
br.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
【问题讨论】:
-
你只有一个 Reader 对象......请在 Stackoverflow 上询问之前对写入文件进行一些研究如何