import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
/*"C:\\Users\\john\\Desktop\\C:\\Users\\john\\Desktop\\成绩统计1.txt"
* 4.
附件中是某班级的连续两次考试成绩,请写个程序,计算出上次考试不及格本次考试超过70分的同学数量及详细信息~~
打印格式:
上次考试不及格,本次超过70分的学生总共有: 2 位!
详细信息如下:
孙允阔 同学: 上次考试成绩为: 58.0 ,本次考试成绩为: 70.0 ,进步很大~~
孟阳 同学: 上次考试成绩为: 18.0 ,本次考试成绩为: 74.0 ,进步很大~~ */
public class work1 {
public static void main(String[] args) throws Exception {
HashMap<String,Double> firstScore = new HashMap<String, Double>();
HashMap<String,Double> secondScore = new HashMap<String, Double>();
System.out.println("请输入:");
firstScore = getMap(firstScore);
System.out.println("请输入:");
secondScore = getMap(secondScore);
getInformation(firstScore,secondScore);
}
private static void getInformation(HashMap<String, Double> firstScore,
HashMap<String, Double> secondScore) {
for(Map.Entry<String, Double> firstEntry:firstScore.entrySet()){
for (Map.Entry<String, Double> secondEntry : secondScore.entrySet()) {
String key = firstEntry.getKey();
Double value = firstEntry.getValue();
String key2 = secondEntry.getKey();
Double value2 = secondEntry.getValue();
if(value<60 && value2>70 && key.equals(key2)){
System.out.println(key+"同学,上次的考试成绩是"+value+"分,本次的考试成绩" +
"是"+value2+"分,进步很大,加油!");
}
}
}
}
private static HashMap<String, Double> getMap(HashMap<String, Double> Score) throws IOException {
Scanner sc = new Scanner(System.in);
String s = sc.next();
FileReader inn = new FileReader(s);
BufferedReader in = new BufferedReader(inn);
String len;
while((len = in.readLine()) != null){
String[] ss = new String[3];
ss=len.split("\\s+");
Score.put(ss[0],Double.valueOf(ss[1]));
}
return Score;
} |