我遇到的问题是,无论如何我可以比较最终的平均工资,然后再次循环并将最终的平均工资与每个工资进行比较,并确定谁是较低的并打印出来并做那个对于每个人我都难以想到这里是我的代码。我应该把人们放在另一个数组列表中并从那里进行比较吗?
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
/**
* Created by Kuroii on 11/3/2014.
*/
public class BelowAverage {
public static void main(String[] args) {
String inputFile = "c:\\Users\\Kuroii\\documents\\javafiles\\sampletwodata.txt";
String strline,FirstNames="",SurNames="",EMPnumbers="";
int totalSalary=0,averageSalary=0,salary=0;
//
ArrayList<String> inputLines = new ArrayList();
try {
FileInputStream fstream = new FileInputStream(inputFile);
BufferedReader inputBuffer = new BufferedReader(new InputStreamReader(fstream));
System.out.println("Starting...");
while ((strline = inputBuffer.readLine()) != null) {
inputLines.add(strline);
}
System.out.print("Read in ");
System.out.print(inputLines.size());
System.out.println(" lines");
} catch (Exception e) {
System.err.println("MB Error reading input file");
}
for (int i = 0; i < inputLines.size(); i++) {
String delim = "[ ]+";
String[] fields = inputLines.get(i).split(delim);
String wage = fields[3];
String hours = fields[4];
FirstNames = fields[1];
EMPnumbers = fields[5];
SurNames = fields[2];
salary = Integer.parseInt(wage) * Integer.parseInt(hours);
totalSalary =totalSalary + salary;
averageSalary = totalSalary/inputLines.size();
}
}
}
答案 0 :(得分:2)
Person
或Employee
的课程,该课程具有描述性变量名称,例如Salary
Person
的集合。称之为people