学生管理系统

学生管理系统

学生管理系统我们要明白一个系统可能设计的几个作用。
1.学生管理系统·首先要可以退出所以必须有退出的设计
2.学生管理嘛当让要录入学生的信息.
3.录入之后我们的脑子并不是强大的计算机记不住太多的东西这个时候就需要查看信息
4.查看的时候万一发现有错误的信息怎么办这个时候就衍生出了删除操作
5.删除的话还需要重新录入显得有点笨拙,何不修改其中的单一信息呢。
就这样一个简单的管理系统就出来了实现最基本的管理操作。

package cn.itcast.Student;

import java.util.LinkedList;
import java.util.Scanner;

public class system {
	public static void main(String[] args) {
		System.out.println("------学生管理系统--------");
		System.out.println("输入0退出管理系统");
		System.out.println("输入1录入学生信息");
		System.out.println("输入2查看录入的学生信息");
		System.out.println("输入3打开删除录入学生信息");
		System.out.println("输入4打开修改录入学生信息");
		LinkedList<Student> information = new LinkedList<Student>();// 创建列表
		while (true) {
			System.out.println("输入要执行的操作序号");
			
			Scanner scan = new Scanner(System.in);
			int conmmand = scan.nextInt();// 接受键盘的输入功能
			// 执行序号功能
			switch (conmmand) {
			case 0:// 退出管理系统
				exit();
				break;
			case 1:// 打开录入学生信息
				addStudentlist(information);
				break;
			case 2:// 查看录入的学生信息
				lookStudentlist(information);
				break;
			case 3:// 打开删除录入学生信息
				deleteStudentlist(information);
				break;
			case 4:// 打开修改录入学生信息
				updateStudentlist(information);
				break;
			default:
				System.out.println("-----------------------");
				System.out.println("功能学则错误,请输入正确的功能序号");
				break;
			}
		}

	}

//打开修改录入学生信息代码
	private static void updateStudentlist(LinkedList<Student> information) {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入要修改的学生学号:");
		String id = scanner.next();
		int result = indexnid(information, id);
		if (result != -1) {
			System.out.println("请输入学生姓名:");
			String name = scanner.next();
			System.out.println("请输入学生年龄:");
			int age = scanner.nextInt();
			Student student = new Student(id, name, age);
			information.set(result, student);
			System.out.println("修改成功");
		} else {
			System.out.println("查无信息,请先添加");
		}
	}

	// 打开删除录入学生信息代码
	private static void deleteStudentlist(LinkedList<Student> information) {
		if (information.isEmpty()) {
			System.out.println("当前无学生信息,请先添加");
		} else {
			Scanner scanner = new Scanner(System.in);
			System.out.println("请输入要删除的学生学号");
			String id = scanner.next();
			int result = indexnid(information, id);
			if (result != -1) {
				information.remove(result);
				System.out.println("删除成功");
			} else {
				System.out.println("学号不存在");
			}
		}

	}

	// 查看录入的学生信息代码
	private static void lookStudentlist(LinkedList<Student> information) {
		if (information.isEmpty()) {
			System.out.println("当前无学生信息,请先添加");
		} else {
			for (Student student : information) {
				System.out.println("学号 姓名 年龄");
				System.out.println(student.getStuid() + ", " + student.getName() + ", " + student.getAge());
			}
		}
	}

	// 打开录入学生信息代码
	private static void addStudentlist(LinkedList<Student> information) {
		Scanner sc = new Scanner(System.in);
		String stuid;
		while (true) {
			System.out.println("请输入学生学号:");
			stuid = sc.next();
			int result = indexnid(information, stuid);
			if (result != -1) {
				System.out.println("学号重复,请检查");
			} else {
				break;
			}
		}
		System.out.println("请输入学生姓名:");
		String name = sc.next();
		System.out.println("请输入学生年龄:");
		int age = sc.nextInt();
		Student student = new Student(stuid, name, age);
		information.add(student);
		System.out.println("添加成功");
	}

	// 退出管理系统代码
	private static void exit() {
		System.out.println("-------退出----------");
		System.out.println("您已退出系统");
		System.exit(0);
	}

	//确保学号唯一性
	private static int indexnid(LinkedList<Student> information, String id) {
		// 假设学号不存在
		int index = -1;
		for (int i = 0; i < information.size(); i++) {
			if (id.equals(information.get(i).getStuid())) {
				index = i;
			}
		}
		return index;
	}
}

class Student {
	private String stuid;
	private String name;
	private int age;

	public Student() {
		super();
	}

	public Student(String stuid, String name, int age) {
		super();
		this.stuid = stuid;
		this.name = name;
		this.age = age;
	}

	public String getStuid() {
		return stuid;
	}

	public void setStuid(String stuid) {
		this.stuid = stuid;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Hackers luthiers

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值