简单的控制台学生信息系统


package studentsystem;


import java.util.ArrayList;
import java.util.Scanner;


public class APP {

ArrayList<Student> list = new ArrayList<Student>();
Scanner input = new Scanner(System.in);
public void start() {
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("---------------------------");

System.out.println("请选择菜单项:");
String index = input.next();

if ("1".equals(index)) {
createStudent();
}else if("2".equals(index)){
findBystuNo();
}else if ("3".equals(index)) {
editStudent();
}else if ("4".equals(index)) {
deleteStudent();
}else if ("5".equals(index)) {
avgStudent();
}else if ("6".equals(index)) {
System.exit(0);
}

}


/**
* 计算学生平均分
*/

private void avgStudent() {
int total = 0;
for (Student stu : list) {
total = total + stu.getScore();
}
int avg = total / list.size();
System.out.println("学生平均分:"+avg);

start();
}




/**
* 删除学生信息
*/


private void deleteStudent() {
System.out.println("请输入学生学号:");
String stuNo = input.next();

Student student = null;

for (Student stu : list) {
if (stu.getStuNo().equals(stuNo)) {
student = stu;
break;
}
}

if (student != null) {
list.remove(student);
System.out.println("删除成功!");
}else{
System.out.println("没有找到该学生信息");
}

start();
}




/**
* 修改学生信息
*/

private void editStudent() {
System.out.println("请输入学生学号:");
String stuNo = input.next();

Student student = null;

for (Student stu : list) {
if (stu.getStuNo().equals(stuNo)) {
student = stu;
break;
}
}

if (student != null) {
System.out.println("请输入新的学生姓名:");
String newName = input.next();

System.out.println("请输入新的学生年龄:");
int newAge = input.nextInt();

System.out.println("请输入新的学生成绩:");
int newScore = input.nextInt();

student.setStuName(newName);
student.setAge(newAge);
student.setScore(newScore);
list.add(student);
System.out.println("信息修改成功!");

}else{
System.out.println("没有找到该学生信息");
}

start();
}




/**
* 根据学号查找学员信息
*/
private void findBystuNo() {
System.out.println("请输入学生学号:");
String stuNo = input.next();

Student student = null;

for (Student stu : list) {
if (stu.getStuNo().equals(stuNo)) {
student = stu;
break;
}
}

if (student != null) {
System.out.println("学生姓名:"+student.getStuName());
System.out.println("学生年龄:"+student.getAge());
System.out.println("学生成绩:"+student.getScore());
} else {
System.out.println("没有找到该学生信息");
}

start();
}




/**
* 录入学员信息
*/
private void createStudent() {

System.out.println("请输入学生学号:");
String stuNo = input.next();

System.out.println("请输入学生姓名:");
String name = input.next();

System.out.println("请输入学生年龄:");
int age = input.nextInt();

System.out.println("请输入学生成绩:");
int score = input.nextInt();

Student stu = new Student();

stu.setStuNo(stuNo);
stu.setStuName(name);
stu.setAge(age);
stu.setScore(score);

list.add(stu);
System.out.println("录入成功!");
start();
}

}




public class Student {


private String stuName;
private String stuNo;
private int age;
private int score;

public String getStuName() {
return stuName;
}
public void setStuName(String stuName) {
this.stuName = stuName;
}
public String getStuNo() {
return stuNo;
}
public void setStuNo(String stuNo) {
this.stuNo = stuNo;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
}


public class Test {
public static void main(String[] args) {

APP app = new APP();

app.start();

}
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值