`

P109学生分数

阅读更多
import java.io.*;
import  java.text.DecimalFormat;
public class StudentGrade{
public static void main(String args[]) throws IOException,FileNotFoundException
{
double test1,test2,test3,test4,test5;
double average;
String firstName;
String lastName;
StringTokenizer tokenizer;
BufferedReader inFile=new BufferedReader(new FileReader("c:\\test.txt"));
PrintWriter outFile=new PrintWriter(new FileWriter("c:\\testavg.out"));
DecimalFormat twoDecimal=new DecimalFormat("0.00");
tokenizer=new StringTokenizer(inFile.readLine());
firstName=tokenizer.nextToken();//???
lastName=tokenizer.nextToken();
outFile.println("Student Name:"+firstName+lastName);
test1=Double.parseDouble(tokenizer.nextToken());
test2=Double.parseDouble(tokenizer.nextToken());
test3=Double.parseDouble(tokenizer.nextToken());
test4=Double.parseDouble(tokenizer.nextToken());
test5=Double.parseDouble(tokenizer.nextToken());

outFile.println("Test scores:"+twoDecimal.format(test1)+
twoDecimal.format(test2)+twoDecimal.format(test3)+twoDecimal.format(test4)+twoDecimal(test5));

average=(test1+test2+test3+test4+test5)/5.0;
outFile.println("Average test score:"+twoDecimal.format(average));
outFile.close();
}
}
//又多处找不到类StringTokenizer,方法twoDecimal  P109学生分数
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics