JAVA简单写学生信息管理系统,实现学生信息的输入、查询、修改、删除操作
package Week;
import jdk.internal.util.xml.impl.Input;
import java.util.HashSet;
import java.util.Scanner;
public class StudentMs {
Scanner sc = new Scanner(System.in);
public int getID() {
return ID;
}
public String getName() {
return name;
}
public String getClassnum() {
return classnum;
}
public int getTelephone() {
return telephone;
}
public void setID(int ID) {
this.ID = ID;
}
public void setName(String name) {
this.name = name;
}
public void setClassnum(String classnum) {
this.classnum = classnum;
}
public void setTelephone(int telephone) {
this.telephone = telephone;
}
private int ID;
private String name;
private String classnum;
private int telephone;
/* public StudentMs(int ID, String name, String classnum, String telephone) {
this.ID = ID;
this.name = name;
this.classnum = classnum;
this.telephone = telephone;
}*/
public void add(StudentMs a){
int ID1;
String name2;
String classnum1;
int telephone1;
System.out.println("请输入你要添加的学生信息");
System.out.println("请输出学生学号");
ID1 =sc.nextInt();
a.setID(ID1);
System.out.println("请输出学生姓名");
sc.nextLine();
name2=sc.nextLine();
a.setName(name2);
System.out.println("请输出学生班级");
classnum1=sc.nextLine();
a.setClassnum(classnum1);
System.out.println("请输出学生电话号码");
telephone1=sc.nextInt();
a.setTelephone(telephone1);
}
public int find(String[][] a)
{
System.out.println("请输入你要查询学生的学号");
int n=-1;
int id = sc.nextInt();
for(int i=0;i<a.length;i++)
{
if(Integer.parseInt(a[i][0]) == id)
{
n=i;
break;
}
}
return n;
}
public int delay(String[][] a)
{
System.out.println("请输入你要删除学生的学号!");
int id;
int n=-1;
id= sc.nextInt();
for(int i=0;i<a.length;i++)
{
if(Integer.parseInt(a[i][0])==id)
{
n=i;
break;
}
}
return n;
}
public int print(String[][] a)
{
System.out.println("请输入你要打印的学生信息的学生学号!");
int id;
int n=-1;
id = sc.nextInt();
for(int i=0;i<a.length;i++)
{
if(Integer.parseInt(a[i][0]) == id)
{
n=i;
break;
}
}
return n;
}
public int recivice(String[][] a)
{
System.out.println("请输入你要修改的学生信息的学生学号!");
int id;
int n=-1;
id = sc.nextInt();
for(int i=0;i<a.length;i++)
{
if(Integer.parseInt(a[i][0]) == id)
{
n=i;
break;
}
}
return n;
}
public int Num(){//用来查找修改图书信息的下标
System.out.println("选择你要修改的内容:0.学号 1.姓名 2.班级 3.电话");
int n=sc.nextInt();
return n;
}
public void display()
{
System.out.println("***************************************");
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("**** 6:退出 ****");
System.out.println("**** 请输入您要进行的操作(1-6) ***");
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
StudentMs studentMs = new StudentMs();
boolean flat = true;
HashSet a = new HashSet();
String[][] student=new String[4][10];
int num=0;
int number;
int m,n;
while (flat)
{
studentMs.display();
number=sc.nextInt();
switch (number)
{
case 1:
{
studentMs.add(studentMs);
student[num][0]=studentMs.ID+"";
student[num][1]=studentMs.name+"";
student[num][2]=studentMs.classnum+"";
student[num][3]=studentMs.telephone+"";
num++;
break;
}
case 2:
{
m=studentMs.find(student);
if(m>=0){
System.out.println("学生学号为:"+student[m][0]);
System.out.println("学生姓名为:"+student[m][1]);
System.out.println("学生班级为:"+student[m][2]);
System.out.println("学生电话为:"+student[m][3]);
}else{
System.out.println("学号错误,未找到学生");
break;
}
break;
}
case 3:
{
m=studentMs.recivice(student);
n=studentMs.Num();
System.out.println("请输入你要修改的内容:");
student[m][n]=sc.next();
System.out.println("修改成功!");
break;
}
case 4:
{
m=studentMs.delay(student);
for(int i=0;i<4;i++)
{
student[m][i]=null;
}
System.out.println("已经成功删除学生信息");
break;
}
case 5:
{
m=studentMs.delay(student);
System.out.println("学号"+student[m][0]+"的学生信息为:");
System.out.println("学生学号为:"+student[m][0]);
System.out.println("学生姓名为:"+student[m][1]);
System.out.println("学生班级为:"+student[m][2]);
System.out.println("学生电话为:"+student[m][3]);
break;
}
case 6:
{
System.out.println("程序退出!");
flat=false;
break;
}
}
}
}
}
代码供大家参考学习,想沟通学习,可以私信或留言,更多项目资料可以供你参考。
代码供大家参考学习,想沟通学习,可以私信或留言,更多项目资料可以供你参考
关注V X公众号 “学享编程”,回复数字1,可免费领取海量学习资料