学生信息管理系统java版
作者:liuyakui 发布时间:2023-06-16 15:48:10
标签:java,学生管理系统
本文为大家分享了java学生信息管理系统的源代码,供大家参考,具体内容如下
/*学生信息管理系统,实现学生信息:
*增加 int[] a=new int[9]
*删除
*查找
*更改
*/
import java.util.Scanner;//导入java输入流
import java.lang.*;
import java.io.*;
class Student
{
private static Student[] s=new Student[2];
int n=0;
private String name;
private int num;
private String classAge;
public void judge()throws IOException
{
int i;
char ch;
String str;
Scanner In=new Scanner(System.in);
if(n==0)
{
System.out.print("你还没有录入任何学生,是否录入(Y/N):");
str=In.next();
ch=str.charAt(0);
while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n')
{
System.out.print("输入有误,请重新输入:");
str=In.next();
ch=str.charAt(0);
}
if(ch=='Y'||ch=='y')
{
this.add();
}
if(ch=='N'||ch=='n')
{
this.menu();
}
}
}
public void menu()throws IOException//定义菜单函数
{
int a;//定义switch语句变量
Scanner in=new Scanner(System.in);//实例化输入流对象
System.out.println("*********学生信息管理系统功能表*********");
System.out.println("***** 1.增加 *****");
System.out.println("***** 2.显示 *****");
System.out.println("***** 3.修改 *****");
System.out.println("***** 4.删除 *****");
System.out.println("***** 5.查看 *****");
System.out.println("***** 0.退出 *****");
System.out.println("****************************************");
System.out.print("请选择(0~5):");
a=in.nextInt();
while(a<0||a>5)
{
System.out.print("输入超出范围,请重新输入:");
a=in.nextInt();
}
switch(a)
{
case 1:this.add();break;
case 2:this.show();break;
case 3:this.modif();break;
case 4:this.delete();break;
case 5:this.look();break;
case 0:System.exit(0);break;
}
}
public void add()throws IOException//定义增加函数
{
String str,str1,str2;
int i,num1,t=1;
char ch,ch1;
FileWriter fw=new FileWriter("F://javaFile//student.txt",true);
fw.write(" 录入的学生信息列表\r\n\r\n学号 姓名 班级\r\n");
Scanner In=new Scanner(System.in);
while(t==1)
{
System.out.print("请输入学生学号:");
num1=In.nextInt();
for(i=0;i<n;i++)
{
while(s[i].num==num1)
{
System.out.println("已存在此学号,请重新输入");
System.out.print("请输入学号:");
num1=In.nextInt();
}
}
s[n].num=num1;
str2=String.valueOf(num1);
fw.write(str2+" ");
System.out.println();
System.out.print("请输入学生姓名:");
s[n].name=In.next();
fw.write(s[n].name+" ");
System.out.println();
System.out.print("请输入学生班级:");
s[n].classAge=In.next();
fw.write(s[n].classAge+"\r\n");
++n;
fw.close();
System.out.println();
System.out.print("是否继续添加(Y/N)");
str=In.next();
ch=str.charAt(0);
while(ch!='N'&&ch!='n'&&ch!='Y'&&ch!='y')
{
System.out.print("输入有误,请重新输入:");
str=In.next();
ch=str.charAt(0);
}
if(ch=='N'||ch=='n')
{
break;
}
}
System.out.println();
System.out.print("是否返回主菜单(Y/N)");
str1=In.next();
ch1=str1.charAt(0);
while(ch1!='Y'&&ch1!='y'&&ch1!='N'&&ch1!='n')
{
System.out.print("输入有误,请重新输入:");
str1=In.next();
ch1=str1.charAt(0);
}
if(ch1=='Y'||ch1=='y')
{
this.menu();
}
if(ch1=='N'||ch1=='n')
{
System.out.println("正在退出...谢谢使用!");
System.exit(0);
}
}
public void show()throws IOException
{
int i;
this.judge();
System.out.println("本次操作共录入"+n+"位学生!");
System.out.println("你录入的学生信息如下:");
System.out.println();
System.out.println("学号\t\t姓名\t班级");
for(i=0;i<n;i++)
{
System.out.println(s[i].num+" "+s[i].name+" "+s[i].classAge);
}
System.out.println("系统返回主菜单!");
this.menu();
}
public void delete()throws IOException//删除信息功能实现 注:本功能暂时不具备可扩展性
{
this.judge();
int j=0,t=0,k=0,num1;
char ch;
String str;
Scanner pin=new Scanner(System.in);
System.out.print("请输入要删除的学号:");
num1=pin.nextInt();
for(j=0;j<n;j++)
{
if(s[j].num==num1)
{
k=1;
t=j;
}
}
if(k==0)
{
System.out.println("对不起!你要删除的学号不存在!");
System.out.println("系统将返回主菜单!");
this.menu();
}
if(k==1)
{
System.out.println("你要删除的学生信息如下:");//打印管理员要删除的学生信息
System.out.println("学号\t姓名\t班级");//本功能暂时不备扩展性
System.out.println(s[t].num+" "+s[t].name+" "+s[t].classAge);
System.out.println();
System.out.print("你确定要删除(Y/N):");
str=pin.next();
ch=str.charAt(0);
while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n')
{
System.out.print("输入有误,请重新输入:");
str=pin.next();
ch=str.charAt(0);
}
if(ch=='N'||ch=='n')
{
System.out.println();
System.out.println("系统返回主菜单!");
this.menu();
}
if(ch=='Y'||ch=='y')
{
for(j=t;j<n-1;j++)
{
s[j]=s[j+1];
}
n--;
System.out.println("数据成功删除!");
System.out.println("系统返回主菜单!");
this.menu();
}
}
}
public void look()throws IOException
{
FileReader fr=new FileReader("F://javaFile//student.txt");
int a;
while((a=fr.read())!=-1)
{
System.out.print((char)a);
}
fr.close();
System.out.println("系统返回主菜单!");
System.out.println();
this.menu();
}
public void modif()throws IOException
{
this.judge();
int j=0,t=0,k=0,num2,num3,moi,c=1;
char ch;
String str,str1,str2;
Scanner pin=new Scanner(System.in);
System.out.print("请输入要修改的学号:");
num2=pin.nextInt();
for(j=0;j<n;j++)
{
if(s[j].num==num2)
{
k=1;
t=j;
}
}
if(k==0)
{
System.out.println("对不起!你要修改的学号不存在!");
System.out.println("系统将返回主菜单!");
this.menu();
}
if(k==1)
{
System.out.println("你要修改的学生信息如下:");//打印管理员要删除的学生信息
System.out.println("学号\t姓名\t班级");//本功能暂时不备扩展性
System.out.println(s[t].num+" "+s[t].name+" "+s[t].classAge);
System.out.println();
System.out.print("你确定要修改(Y/N):");
str=pin.next();
ch=str.charAt(0);
while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n')
{
System.out.print("输入有误,请重新输入:");
str=pin.next();
ch=str.charAt(0);
}
if(ch=='N'||ch=='n')
{
System.out.println();
System.out.println("系统返回主菜单!");
this.menu();
}
while(c==1)
{
if(ch=='Y'||ch=='y')
{
System.out.println("****************************************");
System.out.println("***** 1.修改学号 *****");
System.out.println("***** 2.修改班级 *****");
System.out.println("***** 3.修改姓名 *****");
System.out.println("****************************************");
System.out.print("请选择:");
moi=pin.nextInt();
switch(moi)
{
case 1:System.out.print("请输入新的学号:");num3=pin.nextInt();s[t].num=num3;break;
case 2:System.out.print("请输入新的班级:");str1=pin.next();s[t].classAge=str1;break;
case 3:System.out.print("请输入新的姓名:");str2=pin.next();s[t].name=str2;break;
}
System.out.println("数据已成功修改!");
}
System.out.print("是否继续修改(Y/N)");
str=pin.next();
ch=str.charAt(0);
System.out.println();
while(ch!='Y'&&ch!='y'&&ch!='N'&&ch!='n')
{
System.out.print("输入有误,请重新输入:");
str=pin.next();
ch=str.charAt(0);
}
if(ch=='N'||ch=='n')
{
break;
}
}
}
System.out.println();
System.out.println("系统返回主菜单!");
this.menu();
}
public static void main(String[] args)throws IOException
{
Student stu=new Student();
for(int i=0;i<2;i++)
{
s[i]=new Student();
}
stu.menu();
}
}
更多学习资料请关注专题《管理系统开发》。
来源:http://blog.csdn.net/u010885095/article/details/38848235
0
投稿
猜你喜欢
- 使用对象初始值设定项初始化对象可以使用对象初始值设定项以声明方式初始化类型对象,而无需显式调用类型的构造函数。下面的示例演示如何将对象初始值
- 一、Sharding-JDBC简介Sharding-JDBC是Sharding-Sphere的一个产品,它有三个产品,分别是Sharding
- 什么是线程同步? 当使用多个线程来访问同一个数据时,非常容易出现线程安全问题(比如多个线程都在操作同一数据导致数据不一致),所以我们用同步机
- cpu是时分(time division)的,操作系统里有很多线程,每个线程的运行时间由cpu决定,cpu会分给每个线程一个时间片,时间片是
- 概述java移位符主要包括3种:运算符名称>>左移运算符<<有符号右移运算符<<<无符号右移运算符
- 前言:什么是JDBCJava 数据库连接,(Java Database Connectivity,简称JDBC)是Java语言中用来规范客户
- 1. 你知道线程安全问题吗?线程安全问题:一般指在多线程模式下,多个线程对同一个共享数据进行操作时,第一个线程还没来得及更新共享数据,从而导
- 概述:Flutter 标签类控件大全ChipFlutter内置了多个标签类控件,但本质上它们都是同一个控件,只不过是属性参数不同而已,在学习
- 一、延迟加载resultMap可以实现高级映射(使用association、collection实现一对一及一对多映射),associati
- Mybatis-Plus是一个优秀的Mybatis增强工具,目前更新到3.1.1。Mybatis-Plus原生提供了很多单表操作的方法,极大
- 1.最常用的方法是创建一个计数器,判断是否遇到‘\0',不是'\0'指针就往后加一。int my_strlen(co
- 直接插入排序直接插入排序的思路很容易理解,它是这样的:1.把待排序的数组分成已排序和未排序两部分,初始的时候把第一个元素认为是已排好序的。2
- 这篇文章主要介绍了Spring如何在一个事务中开启另一个事务,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需
- 前言小小知识,不值一提,了解了也不能让你提高身价,但是不了解你就是比别人少知道点!事儿就是这么个事儿,直接正题吧! 直接看代码演示优先级当方
- 官网教程一、翻转(镜像)头文件 quick_opencv.h:声明类与公共函数#pragma once#include <opencv
- 本文实例讲述了Java排序算法总结之希尔排序。分享给大家供大家参考。具体分析如下:前言:希尔排序(Shell Sort)是插入排序的一种。是
- 本文实例为大家分享了Java解码H264格式视频流中的图片,供大家参考,具体内容如下引入依赖<dependency>  
- 安全无处不在,趁着放假读了一下 Shiro 文档,并记录一下 Shiro 整合 Spring Boot 在数据库中根据角色控制访问权限简介A
- 前段时间学习JDBC,要连接mysql获取数据。按照老师的样例数据,要存一些名字之类的信息,用的都是英文名,我当时就不太想用英文,就把我室友
- 1. 安装JDK解释: JDK是Java编写环境--开发环境注: 安装路径不可出现中文及标点符号。比如:D:\Java\jdk81.1 下载