⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 start.java

📁 一个没有数据库连接的小型学生信息管理系统
💻 JAVA
字号:
package com.yhwpeng;
/**
 * @author 王栋
 * @version 1.0 2008-8-12
 * 开发/测试环境:jdk1.6 + myEclipse 6.0.1
 */
import java.util.*;

class Student {
	Scanner input = new Scanner(System.in);
	int[] stuNo = new int[35];
	String[] stuName = new String[35];
	int[] stuAge = new int[35];
	String[] stuSex = new String[35];

	public double exam() {
		double score = Math.round(10000 * (Math.random()) % 100);
		return score;
	}

	public void initial() {
		stuNo[0] = 01;
		stuName[0] = "杨帆";
		stuAge[0] = 21;
		stuSex[0] = "男";
		stuNo[1] = 02;
		stuName[1] = "王旭";
		stuAge[1] = 22;
		stuSex[1] = "男";
		stuNo[2] = 03;
		stuName[2] = "马鸣";
		stuAge[2] = 23;
		stuSex[2] = "男";
	}



	public void showOutput() {
		System.out.println("学号\t姓名\t年龄\t性别\t成绩");
		for (int i = 0; i < stuNo.length; i++) {
			if (stuNo[i] == 0) {
				break;
			}
			System.out.println(stuNo[i] + "\t" + stuName[i] + "\t" + stuAge[i]
					+ "\t" + stuSex[i] + "\t" + exam());
		}
	}
}

class Team {
	Student stu = new Student();
	Scanner input = new Scanner(System.in);

	public void showMainMenu() {
		System.out.println("\n\n\t\t\t\t 欢迎使用学生信息管理系统\n");
		System.out
				.println("*********************************************************************************\n");
		System.out.println("\t\t\t 1. 显 示 所 有 学 生 信 息\n");
		System.out.println("\t\t\t 2. 添 加 学 生 信 息\n");
		System.out.println("\t\t\t 3. 删 除 学 生 信 息\n");
		System.out.println("\t\t\t 4. 修 改 学 生 信 息\n");
		System.out.println("\t\t\t 5. 查 询 学 生 信 息\n");
		System.out.println("\t\t\t 0. 退 出 系 统\n");
		System.out
				.println("*********************************************************************************\n");

		boolean con = false;
		int no;
		do {

			no = input.nextInt();
			if (no == 1) {
				stu.initial();
				stu.showOutput();
			} else if (no == 2)
				add();
			else if (no == 3) {
				sub();
			} else if (no == 4) {
				
				change();
			} else if (no == 5) {
				search();
			} else if (no == 0){
				System.out.println("谢谢使用,祝您愉快!");
				return ;
			}
			else {
				System.out.print("输入错误,请重新输入数字:");
				con = true;
			}
		} while (con);
		System.out.print("按0键返回上一级菜单:");
		no = input.nextInt();
		while (no != 0) {
			System.out.println("输入错误,请重新输入:");
			no = input.nextInt();
		}
		showMainMenu();
	}

	// 添加学生信息
	public void add() {
		stu.showOutput();
		System.out.println("\n");
		System.out.println("学生信息管理系统>添加学生信息\n\n");
		String choice;
		do {
			System.out.print("请输入学号:");
			int no = input.nextInt();
			System.out.print("请输入学生姓名:");
			String name = input.next();
			System.out.print("请输入学生年龄:");
			int age = input.nextInt();
			System.out.print("请输入学生性别:");
			String sex = input.next();
			int index = -1;
			for (int i = 0; i < stu.stuNo.length; i++) {
				if (stu.stuNo[i] == 0) {
					index = i;
					break;
				}
			}
			stu.stuNo[index] = no;
			stu.stuName[index] = name;
			stu.stuAge[index] = age;
			stu.stuSex[index] = sex;
			System.out.println("继续添加学生信息么(y/n)?");
			choice = input.next();
		} while (choice.equals("y"));
		System.out.println("添加成功!");
		stu.showOutput();
	}

	// 删除学生信息
	public void sub() {
		stu.showOutput();
		String choice;
		System.out.println("\n");
		System.out.println("学生信息管理系统>删除学生信息\n\n");
		do {
			System.out.println("请输入您要删除的学生学号:");
			int no = input.nextInt();
			for (int i = no; i < stu.stuNo.length; i++) {
				stu.stuNo[i - 1] = stu.stuNo[i];
				stu.stuName[i - 1] = stu.stuName[i];
				stu.stuAge[i - 1] = stu.stuAge[i];
				stu.stuSex[i - 1] = stu.stuSex[i];
			}
			System.out.println("继续删除学生信息么(y/n)?");
			choice = input.next();
		} while (choice.equals("y"));
		System.out.println("删除成功!");
		stu.showOutput();
	}

	// 修改学生信息
	public void change() {
		stu.showOutput();
		String choice;
		System.out.println("\n");
		System.out.println("学生信息管理系统>修改学生信息\n\n");
		do {
			System.out.println("请输入您要修改的学生学号:");
			int no = input.nextInt();
			for (int i = (no - 1); i < stu.stuNo.length; i++) {
				System.out.print("修改姓名:");
				stu.stuName[i] = input.next();
				System.out.print("修改年龄:");
				stu.stuAge[i] = input.nextInt();
				System.out.print("修改性别:");
				stu.stuSex[i] = input.next();
				break;
			}
			System.out.println("继续修改学生信息么(y/n)?");
			choice = input.next();
		} while (choice.equals("y"));
		System.out.println("修改成功!");
		stu.showOutput();

	}

	// 查询学生信息
	public void search() {
		stu.showOutput();
		String choice;
		System.out.println("\n");
		System.out.println("学生信息管理系统>查询学生信息\n\n");
		do {
			System.out.println("请输入您要查询的学生学号:");
			int no = input.nextInt();
			int first = 0;
			int index=-1;
			for(int i=0;i<stu.stuNo.length;i++){
				if(stu.stuNo[i]==0){
					index=i;
					break;
				}
				
			}
			int last = index;
			int mid;
			while (first <= last) {
				mid = (first + last) / 2;
				if (stu.stuNo[mid] == no){
					System.out.println("学号\t姓名\t年龄\t性别\t成绩");
				System.out.println(stu.stuNo[no-1] + "\t" + stu.stuName[no-1]
						+ "\t" + stu.stuAge[no-1] + "\t" + stu.stuSex[no-1] + "\t"
						+ stu.exam());
				break;
				}
				if (stu.stuNo[mid] > no)
					last = mid - 1;
				if (stu.stuNo[mid] <no)
					first = mid + 1;
			}
			System.out.println("继续查询学生信息么(y/n)?");
			choice = input.next();
		} while (choice.equals("y"));

	}
}

public class Start {

	/**
	 * @author王栋
	 * @version 0.1
	 * @data 2008年8月12日
	 * @environment MyEclips6.0+JDK1.6
	 */
	public static void main(String[] args) {
		Team team = new Team();
		team.showMainMenu();

	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -