基本的学生信息管理项目

import java.util.Scanner;

public class Kahdjsd {

	static int index = 0;
	static Students[] students = new Students[45];

	public static void main(String[] args) {

		System.out.println("----------------");
		System.out.println("欢迎使用学生信息管理系统!");
		System.out.println("----------------");

		for (;;) {
			menu();
		}

	}

	private static void menu() {
		System.out.println("1.添加学生信息");
		System.out.println("2.删除学生信息");
		System.out.println("3.修改学生信息");
		System.out.println("4.查询学生信息");
		System.out.println("请输入操作项,并点击Enter键");
		Scanner scanner = new Scanner(System.in);
		int option = scanner.nextInt();
		switch (option) {
		case 1: {
			if (index > students.length) {
				System.out.println("已经没有位置!");
				return;
			}
			Students student = new Students();
			System.out.println("请输入学号,并点击Enter健");
			String id = scanner.next();
			student.setId(id);
			System.out.println("请输入姓名,并点击Enter健");
			String name = scanner.next();
			student.setName(name);
			System.out.println("请输入电话号码,并点击Enter健");
			String mobile = scanner.next();
			student.setMobile(mobile);
			;
			System.out.println("请输入家庭住址,并点击Enter健");
			String address = scanner.next();
			student.setAddress(address);
			if (index != 0) {

				for (Students stu : students) {
					if (stu == null) {
						break;
					}
					if (stu.getId().equals(student.getId())) {
						System.out.println("学号重复!请重新输入!");
						return;
					}
				}
			}

			students[index] = student;
			index = index + 1;
			System.out.println(index);
			System.out.println("添加学生信息成功!");
			return;
		}
		case 2: {
			System.out.println("请输入要删除的学生学号");
			String id = scanner.next();
			for (int y = 0; y < 45; y++) {
				if (students[y] == null) {
					System.out.println("该学号不存在");
					return;
				}
				if (students[y].getId().endsWith(id)) {
					for (int h = y; h < 45; h++) {
						if (students[h + 1] == null) {
							System.out.println("删除成功");
							return;
						} else {
							students[h] = students[h + 1];
						}

					}

				}
			}

			return;
		}
		case 3: {
			System.out.println("请输入要修改学生信息的学生学号");
			String id = scanner.next();
			for (int y = 0; y < 45; y++) {
				if (students[y] == null) {
					System.out.println("该学号不存在");
					return;
				}
				if (students[y].getId().equals(id)) {
					System.out.println("请输入学生姓名");
					String n = scanner.next();
					students[y].setName(n);
					System.out.println("请输入学生电话号码");
					String m = scanner.next();
					students[y].setMobile(m);
					System.out.println("请输入学生家庭住址");
					String a = scanner.next();
					students[y].setAddress(a);
					System.out.println("修改学生信息成功");
					return;
				}
			}
			return;
		}
		case 4: {
			boolean hasDate = false;
			System.out.println("请输入要查询信息的学生学号");
			String id = scanner.next();
			for (Students student : students) {
				if (student == null) {
					return;
				}
				if (student.getId().equals(id)) {
					System.out.println("学号为:" + student.getId());
					System.out.println("姓名为:" + student.getName());
					System.out.println("电话号码为:" + student.getMobile());
					System.out.println("地址为:" + student.getAddress());
					hasDate = true;
					return;
				}

			}
			if (!hasDate) {
				System.out.println("该学号的学生信息不存在!");
			}
			return;
		}
		default:
			System.out.println(option + "操作项不存在!");
		}
	}

}

 

发布了18 篇原创文章 · 获赞 0 · 访问量 212
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 深蓝海洋 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览