博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
基于java实现学生信息管理系统单机对话版
阅读量:3949 次
发布时间:2019-05-24

本文共 6138 字,大约阅读时间需要 20 分钟。

实验要求

控制类(主类):Manage

import java.util.ArrayList;import java.util.Collections;import java.util.Comparator;import java.util.List;import java.util.Scanner;public class Manage{
static List
studentList=new ArrayList<>(); static List
allscores=new ArrayList<>(); static Scanner in=new Scanner(System.in); public static void main(String[] args) {
int ty = 10; while(ty!=0) {
System.out.println("1.添加学生"); System.out.println("2.删除学生"); System.out.println("3.修改学生"); System.out.println("4.查看学生"); System.out.println("5.增加学生课程学习记录"); System.out.println("6.查看所有学生信息(排序)"); System.out.println("7.平均分、最高分、最低分"); System.out.println("8.成绩单"); System.out.println("0.退出系统"); ty=in.nextInt(); switch(ty) {
case 1: addStudent(); break; case 2: remove(); break; case 3:fix(); break; case 4:find(); break; case 5:addscore(); break; case 6:sort(); break; case 7:printscore(); break; case 8:findall(); break; case 0:break; default:System.out.println("请重新输入"); } } System.out.println("系统退出成功!"); } public static void addStudent() {
Student student=new Student(); System.out.println("请输入名字:"); student.getname(in.next()); System.out.println("请输入学号:"); student.getnum(in.nextInt()); studentList.add(student); studentList.get(studentList.size()-1).studentScores.add(new Score()); System.out.println("添加成功!"); } public static void addscore() {
System.out.println("请输入要增加课程成绩记录学生学号:"); int p=in.nextInt(); int t=0; for (int i = 0; i < studentList.size(); i++) {
if (p==studentList.get(i).tonum()) {
studentList.get(i).studentScores.add(new Score()); System.out.println("添加课程成绩成功"); t=1; } } if (t==0) {
System.out.println("没有找到学号为:"+p+"学生"); } } public static void remove() {
System.out.println("请输入要删除学生的学号:"); int p=in.nextInt(); int t=0; for (int i = 0; i < studentList.size(); i++) {
if (p==studentList.get(i).tonum()) {
studentList.remove(i); t=1; } } if (t==0) {
System.out.println("没有找到学号为:"+p+"学生"); } } public static void fix() {
System.out.println("请输入要修改信息的学生学号:"); int p=in.nextInt(); int t=0; int t1=0; String scString; for (int i = 0; i < studentList.size(); i++) {
if (p==studentList.get(i).tonum()) {
System.out.println("请输入要修改课程(全称):"); scString=in.next(); for (int j = 0; j < studentList.get(i).studentScores.size(); j++) {
if (scString.equals(studentList.get(i).studentScores.get(j).course)) {
//scString==(studentList.get(i).studentScores.get(j).course恶意出错 System.out.println("请输入要修改此门课:"+scString+"的成绩:"); studentList.get(i).studentScores.get(j).score=in.nextInt(); t1=1; } } if (t1==0) {
System.out.println("没有找到课程为:"+scString+"的课程"); } t=1; } } if (t==0) {
System.out.println("没有找到学号为:"+p+"学生"); } } public static void find() {
System.out.println("请输入要查找信息的学生学号:"); int p=in.nextInt(); int t=0; for (int i = 0; i < studentList.size(); i++) {
if (p==studentList.get(i).tonum()) {
System.out.println("该生信息如下:"); System.out.println("学号:"+studentList.get(i).tonum()); System.out.println("姓名:"+studentList.get(i).toname()); for (int j = 0; j < studentList.get(i).studentScores.size(); j++) {
System.out.println("课程:"+studentList.get(i).studentScores.get(j).course); System.out.println("成绩:"+studentList.get(i).studentScores.get(j).score); } t=1; } } if (t==0) {
System.out.println("没有找到学号为:"+p+"学生"); } } public static void sort() {
for (int i = 0; i < studentList.size(); i++) {
Collections.sort(studentList.get(i).studentScores,new Comparator
() {
@Override public int compare(Score o1, Score o2) {
// TODO 自动生成的方法存根 return -o1.score+o2.score; } }); } findall(); } public static void findall() {
for (int i = 0; i < studentList.size(); i++) {
System.out.println("学号:"+studentList.get(i).num+" "+"姓名:"+studentList.get(i).name); for (int j = 0; j < studentList.get(i).studentScores.size(); j++) {
System.out.println("课程:"+studentList.get(i).studentScores.get(j).course+" "+"成绩:"+studentList.get(i).studentScores.get(j).score); } } } public static void printscore() {
System.out.println(allscores.size()); for (int i = 0; i < allscores.size(); i++) {
System.out.println("课程:"+allscores.get(i).course+" "+"人数:"+allscores.get(i).pepnumsum+" "+"总分:"+allscores.get(i).scoresum+" "+"平均分:"+allscores.get(i).scoresum/allscores.get(i).pepnumsum+" "+"最高分:"+allscores.get(i).heightest+" "+"最低分:"+allscores.get(i).lowest); } }}```> 学生类:Student```javaimport java.util.ArrayList;import java.util.List;public class Student {
public String name; public int num; public List
studentScores=new ArrayList<>(); public void getname(String name) {
this.name=name; } public void getnum(int num) {
this.num=num; } public String toname() {
return name; } public int tonum() {
return num; }}

添加成绩记录类:Score

import java.util.Scanner;public class Score extends Manage{
public String course; public int score; Score() {
Scanner scannerin=new Scanner(System.in); System.out.println("请输入要添加的课程:"); this.course=scannerin.next(); System.out.println("请输入此门课程的成绩:"); this.score=scannerin.nextInt(); Allscore h=new Allscore(this.course, this.score); if (h.p==1) {
allscores.add(h); } } }

统计平均分,最高分,最低分类:Allscore

public class Allscore extends Manage{
public String course; public int scoresum; public int pepnumsum; public int heightest; public int lowest; public int p=1; public Allscore(String course, int score) {
for (int i = 0; i < allscores.size(); i++) {
if (course.equals(allscores.get(i).course)) {
allscores.get(i).scoresum+=score; allscores.get(i).pepnumsum+=1; if (allscores.get(i).heightest
score) {
allscores.get(i).lowest=score; } p=0; } } if (p==1) {
this.course=course; this.scoresum=score; this.heightest=score; this.lowest=score; this.pepnumsum=1; } }}

之后我会实现一个界面版,敬请期待

转载地址:http://zorwi.baihongyu.com/

你可能感兴趣的文章
惰性求值,可组合和模块化的JavaScript
查看>>
How to Extend Django User Model 如何扩展Django用户模型
查看>>
两个行业的故事:编程语言与富裕国家和发展中国家之间的差异
查看>>
15个用于管理MySQL服务器mysqladmin命令
查看>>
服务器端I / O性能:Node,PHP,Java与Go
查看>>
多行文本编辑时,同一行编辑不同类型的字符时自动换行的问题
查看>>
如何使开机动画只播一次
查看>>
如何在平台上实现LED灯的效果?如信号灯,来短信/来电时LED动画闪烁
查看>>
restore factory属性的enable和disable
查看>>
Android LOG机制流程图
查看>>
如何在JNI中抛异常
查看>>
Android应用程序的完全退出
查看>>
Task和Activity相关的一些属性
查看>>
JAVA系统属性之user.home
查看>>
Android代码截屏
查看>>
Android中打印代码的调用层次
查看>>
成功者十三个价值连城的习惯
查看>>
特别成功的人会做6件事
查看>>
Android: 用jni 获取MAC地址
查看>>
字符串列表的C语言实现:c_strlist
查看>>