求JAVA源代码
1、编写一个java成绩统计程序,输入一个班的java成绩(含姓名和分数),统计出平均分,最高分、最低分,并打印成绩单。由于编程时人数不确定,所以要求使用Vector或A...
1、编写一个java成绩统计程序,输入一个班的java成绩(含姓名和分数),统计出平均分,最高分、最低分,并打印成绩单。由于编程时人数不确定,所以要求使用Vector或ArrayList完成上述程序。
1)学生成绩用一个类Mark表示,其成员变量包含考生姓名、成绩。输入的姓名为"end"时,程序结束。
2)主类的名称叫做GradeStatistic,将Mark设计为GradeStatistic的内部类。
提示:键盘输入采用Scanner类,实例化Scanner采用下述语句:
Scanner sc=new Scanner(System.in);
然后通过sc调用Scanner的各种方法输入相应的数据。 展开
1)学生成绩用一个类Mark表示,其成员变量包含考生姓名、成绩。输入的姓名为"end"时,程序结束。
2)主类的名称叫做GradeStatistic,将Mark设计为GradeStatistic的内部类。
提示:键盘输入采用Scanner类,实例化Scanner采用下述语句:
Scanner sc=new Scanner(System.in);
然后通过sc调用Scanner的各种方法输入相应的数据。 展开
2个回答
展开全部
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class GradeStatistic {
public static void main(String[] args) {
GradeStatistic gs = new GradeStatistic();
List<Mark> list = new ArrayList<Mark>();
float sum = 0;
while(true){
Scanner sc = new Scanner(System.in);
System.out.print("Please input student name: ");
String name = sc.nextLine();
if(name.equals("end")){
break;
}
System.out.print("Please input student score: ");
float score = sc.nextFloat();
sum += score;
list.add(gs.new Mark(name, score));
}
float max = list.get(0).getScore();
float min = list.get(0).getScore();
for(Mark mark: list){
if(max < mark.getScore()){
max = mark.getScore();
}
if(min > mark.getScore()){
min = mark.getScore();
}
}
float average = sum / list.size();
System.out.println("Average is: " + average);
System.out.println("Max is: " + max);
System.out.println("Min is: " + min);
}
private class Mark{
private String name;
private float score;
public Mark(String name, float score){
this.name = name;
this.score = score;
}
public String getName() {
return name;
}
public float getScore() {
return score;
}
}
}
----------------------
Please input student name: Zhang san
Please input student score: 100
Please input student name: Li Si
Please input student score: 91
Please input student name: Ec
Please input student score: 35
Please input student name: ma qi
Please input student score: 67
Please input student name: end
Average is: 73.25
Max is: 100.0
Min is: 35.0
import java.util.List;
import java.util.Scanner;
public class GradeStatistic {
public static void main(String[] args) {
GradeStatistic gs = new GradeStatistic();
List<Mark> list = new ArrayList<Mark>();
float sum = 0;
while(true){
Scanner sc = new Scanner(System.in);
System.out.print("Please input student name: ");
String name = sc.nextLine();
if(name.equals("end")){
break;
}
System.out.print("Please input student score: ");
float score = sc.nextFloat();
sum += score;
list.add(gs.new Mark(name, score));
}
float max = list.get(0).getScore();
float min = list.get(0).getScore();
for(Mark mark: list){
if(max < mark.getScore()){
max = mark.getScore();
}
if(min > mark.getScore()){
min = mark.getScore();
}
}
float average = sum / list.size();
System.out.println("Average is: " + average);
System.out.println("Max is: " + max);
System.out.println("Min is: " + min);
}
private class Mark{
private String name;
private float score;
public Mark(String name, float score){
this.name = name;
this.score = score;
}
public String getName() {
return name;
}
public float getScore() {
return score;
}
}
}
----------------------
Please input student name: Zhang san
Please input student score: 100
Please input student name: Li Si
Please input student score: 91
Please input student name: Ec
Please input student score: 35
Please input student name: ma qi
Please input student score: 67
Please input student name: end
Average is: 73.25
Max is: 100.0
Min is: 35.0
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
师傅你太不厚道了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询