public static void main(String[] args) throws FileNotFoundException {
double agentID;
String type;
double price;
Set<String> types = new TreeSet<String>();
Map<Double, Double> agents = new TreeMap<Double, Double>();
Scanner console = new Scanner(System.in);
String propertyID;
double totalPrice = 0;
System.out.print ("Please enter file name: ");
String inputFileName = console.next();
File inputFile = new File(inputFileName);
Scanner in = new Scanner(inputFile);
while (in.hasNextLine()) {
propertyID = in.next();
type = in.next();
price = in.nextDouble();
agentID = in.nextDouble();
type = type.toUpperCase();
types.add(type);
if (agents.containsValue(agentID)) {
agents.put(agentID, agents.get(agentID)+price);
}
else {
totalPrice = price;
agents.put(agentID, totalPrice);
}
}
in.close();
System.out.println(types);
System.out.println(agents);
}
我正在尝试更新地图中totalPrice
的值agentID
是否已包含在agents
地图中。当我运行程序时,它会输出分配给键的初始值,agentID
但不会输出totalPrice + price
. 我已经查看了这里的问题并查看了 API 文档,但我没有取得任何进展。任何帮助,将不胜感激。