java编写学生成绩管理系统
有5个学生,每个学生有2门课成绩,从键盘上输入以上数据(学生信息包括学号、姓名,以及2门课成绩),保存在一个文本文件中。计算出每个学生的总成绩,并将学生数据(包括学生2门...
有5个学生,每个学生有2门课成绩,从键盘上输入以上数据(学生信息包括学号、姓名,以及2门课成绩),保存在一个文本文件中。
计算出每个学生的总成绩,并将学生数据(包括学生2门课的总成绩)按总分由高到低排序后保存到磁盘文件sort.txt中。
统计平均成绩,不及格比例,及格比例、优良中所占比例。
要求用菜单方式选择功能 展开
计算出每个学生的总成绩,并将学生数据(包括学生2门课的总成绩)按总分由高到低排序后保存到磁盘文件sort.txt中。
统计平均成绩,不及格比例,及格比例、优良中所占比例。
要求用菜单方式选择功能 展开
展开全部
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Admin {
public static void main(String[] args) throws IOException, ClassNotFoundException {
Scanner in = new Scanner(System.in);
int studentNum = 5;
List<Student> result = new ArrayList<Student>();
for (int i = 0; i < studentNum; i++) {
Student bean = new Student();
System.out.print("输入第" + (i + 1) + "个学生学号:");
bean.setNo(in.next());
System.out.print("输入第" + (i + 1) + "个学生姓名:");
bean.setName(in.next());
System.out.print("输入第" + (i + 1) + "个学生数学成绩:");
bean.setShuxue(in.nextDouble());
System.out.print("输入第" + (i + 1) + "个学生语文成绩:");
bean.setYuwen(in.nextDouble());
result.add(bean);
}
while (true) {
System.out.println("1.保存到文件;2.总成绩;3.平均成绩;4.不及格比例;5.及格比例;6,优良比例;0.退出.");
int i = in.nextInt();
if (i == 0) {
System.exit(0);
}
if (i == 1) {
save(result);
}
if (i == 2) {
for (int j = 0; j < result.size(); j++) {
Student s = result.get(j);
System.out.println("学生" + s.getName() + "的总成绩是:" + s.all());
}
}
if (i == 3) {
int jigeSum = 0;
for (int j = 0; j < result.size(); j++) {
Student s = result.get(j);
if (!s.isJige()) {
jigeSum++;
}
}
System.out.println("不及格比例:" + jigeSum + "/" + result.size());
}
if (i == 4) {
// 篇幅受限,自行开发
}
if (i == 5) {
// 篇幅受限,自行开发
}
}
}
private static void save(List result) throws IOException {
FileOutputStream fs = new FileOutputStream("d:/a.txt");
ObjectOutputStream os = new ObjectOutputStream(fs);
os.writeObject(result);
os.flush();
os.close();
fs.close();
}
}
class Student implements Serializable {
private String no;
private String name;
private double shuxue;
private double yuwen;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNo() {
return no;
}
public void setNo(String no) {
this.no = no;
}
public double getShuxue() {
return shuxue;
}
public void setShuxue(double shuxue) {
this.shuxue = shuxue;
}
public double getYuwen() {
return yuwen;
}
public void setYuwen(double yuwen) {
this.yuwen = yuwen;
}
public double all() {
return shuxue + yuwen;
}
public double avg() {
return all() / 2;
}
public boolean isJige() {
return avg() > 60;
}
}
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Admin {
public static void main(String[] args) throws IOException, ClassNotFoundException {
Scanner in = new Scanner(System.in);
int studentNum = 5;
List<Student> result = new ArrayList<Student>();
for (int i = 0; i < studentNum; i++) {
Student bean = new Student();
System.out.print("输入第" + (i + 1) + "个学生学号:");
bean.setNo(in.next());
System.out.print("输入第" + (i + 1) + "个学生姓名:");
bean.setName(in.next());
System.out.print("输入第" + (i + 1) + "个学生数学成绩:");
bean.setShuxue(in.nextDouble());
System.out.print("输入第" + (i + 1) + "个学生语文成绩:");
bean.setYuwen(in.nextDouble());
result.add(bean);
}
while (true) {
System.out.println("1.保存到文件;2.总成绩;3.平均成绩;4.不及格比例;5.及格比例;6,优良比例;0.退出.");
int i = in.nextInt();
if (i == 0) {
System.exit(0);
}
if (i == 1) {
save(result);
}
if (i == 2) {
for (int j = 0; j < result.size(); j++) {
Student s = result.get(j);
System.out.println("学生" + s.getName() + "的总成绩是:" + s.all());
}
}
if (i == 3) {
int jigeSum = 0;
for (int j = 0; j < result.size(); j++) {
Student s = result.get(j);
if (!s.isJige()) {
jigeSum++;
}
}
System.out.println("不及格比例:" + jigeSum + "/" + result.size());
}
if (i == 4) {
// 篇幅受限,自行开发
}
if (i == 5) {
// 篇幅受限,自行开发
}
}
}
private static void save(List result) throws IOException {
FileOutputStream fs = new FileOutputStream("d:/a.txt");
ObjectOutputStream os = new ObjectOutputStream(fs);
os.writeObject(result);
os.flush();
os.close();
fs.close();
}
}
class Student implements Serializable {
private String no;
private String name;
private double shuxue;
private double yuwen;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNo() {
return no;
}
public void setNo(String no) {
this.no = no;
}
public double getShuxue() {
return shuxue;
}
public void setShuxue(double shuxue) {
this.shuxue = shuxue;
}
public double getYuwen() {
return yuwen;
}
public void setYuwen(double yuwen) {
this.yuwen = yuwen;
}
public double all() {
return shuxue + yuwen;
}
public double avg() {
return all() / 2;
}
public boolean isJige() {
return avg() > 60;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询