高分悬赏Java写程序,要求自己亲自运行过没问题的 谢谢 追加分!不要随便复制给我的。

有五个学生,每个学生有3门课的成绩,从键盘输入以上数据(包括学生号,姓名,三门课成绩),计算出平均成绩,把原有的数据和计算出的平均分数存放在磁盘文件 "stud "中。
做的好的 留下支付宝账号 有惊喜给你

分为两个类编写。第一个类:

package study;


class Student{
// 由键盘输入3个学生成绩(国文、英文、数学),并算出其平均
private int id ;
private String name ;
private int gy ;
private int wy ;
private int sx ;
public Student(int id,String name,int gy,int wy,int sx) {
this.id=id;
this.name = name;
this.gy = gy;
this.wy = wy;
this.sx = sx;
}

public String toString(){
return "学生ID:"+this.id+"姓名:" + this.name + ";国语成绩:"
+ this.gy+";外语成绩:"+ this.wy+";数学成绩:"+ this.sx+
";平均成绩:"+ (this.gy+ this.wy+ this.sx )/3;
}
}
第二个类:

package study;
import java.io.*;
import java.util.Scanner;
public class Test {
public static void main(String[] args)throws Exception {
Scanner s = new Scanner(System.in);
 Student[] stu =  new Student[3];
 for (int i = 0; i < stu.length; i++) {
System.out.print("请输入第"+(i+1)+"个学生的ID:");
int id=s.nextInt();
System.out.print("请输入第"+(i+1)+"个学生的姓名:");
String name=s.next();
System.out.print("请输入第"+(i+1)+"个学生的国语成绩:");
int gy=s.nextInt();
System.out.print("请输入第"+(i+1)+"个学生的外语成绩:");
int wy=s.nextInt();
System.out.print("请输入第"+(i+1)+"个学生的数学成绩:");
int sx=s.nextInt();
stu[i]=new Student(id, name, gy, wy, sx);
}
 PrintStream ps = null ;// 声明打印流对象
ps = new PrintStream(new FileOutputStream(new File("d:" + File.separator + "stud.txt"))) ;
for(int i = 0; i < stu.length; i++){
ps.println(stu[i]);
}
}
}

亲测可行,生成文件在D盘的stud.txt文件中,最近正在学习,可以互相交流,支付宝就免了

追问

要求平均分的 这个好像没求

追答

求了,你自己运行一下,在toString方法中求的,直接写入文件中
打印形式给你复制了一个:
学生ID:123456姓名:张三;国语成绩:80;外语成绩:70;数学成绩:80;平均成绩:76
对了,你有五个学生,把 Student[] stu = new Student[3];中的3改成5就好了

追问

搞了半天 我都不知道怎么运行 两个类 我不是这个专业的 只是为了应付作业 大神 求帮忙!

追答

留下联系方式,可以指导你,你也可以找学长

追问

企鹅770753549

温馨提示:答案为网友推荐,仅供参考
相似回答
大家正在搜