我还是没搞懂。。你既然txt里都写好了提成多少了,直接拿出来输出不就得了吗,怎么还要计算啊。。
按照我的理解,简单地给你写了一个程序,源码是:
import java.util.*;
import java.io.*;
public class Ex
{
public static void main(String[] args)
{
ArrayList employees = new ArrayList();
try
{
//txt文件路径一定要放在启动路径下,名称为Test.txt。如果需要的话可以自己改动
Scanner in = new Scanner(new File("Test.txt"));
//读取总额
Employee.total = in.nextInt();
//读取每个雇员信息
while (in.hasNext())
{
Employee temp = new Employee();
temp.name = in.next();
temp.rate = in.nextDouble();
temp.sum = temp.rate * Employee.total;
employees.add(temp);
}
in.close();
//遍历每个雇员并输出
System.out.println("姓名\t比例\t总额");
for (Employee i : employees)
{
System.out.println(i.name + "\t" + i.rate + "\t"
+ i.sum);
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
class Employee
{
public String name;//姓名
public double rate;//比例
public double sum;//提成多少
public static int total;//总额
}
Test.txt文件格式如下:
10000
李守东 0.01
徐贤坤 0.03