当前位置:网站首页>学生管理系统
学生管理系统
2022-07-27 05:01:00 【new一个对象_】
*创建Student类存放学生学号,姓名,年龄,家庭居住地址
package 学生管理系统;
public class Student {
private String num;
private String name;
private String age;
private String id;
public Student() {
}
public Student(String num, String name, String age, String id) {
this.num = num;
this.name =name;
this.age = age;
this.id = id;
}
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
//创建studentManagement类对学生信息进行增删改查操作
package 学生管理系统;
import java.util.ArrayList;
import java.util.Scanner;
public class studentManagement {
public static ArrayList<Student>a=new ArrayList<>();
public static void main(String[] args) {
ArrayList<Student> a = new ArrayList<>();
while (true) {
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("请输入您的选择");
Scanner in = new Scanner(System.in);
int s = in.nextInt();
switch (s) {
case 1:
addStudent(a);
break;
case 2:
deleteStudent(a);
break;
case 3:
removeStudent(a);
break;
case 4:
findStudent(a);
break;
case 5:
System.out.println("退出");
System.exit(0);
}
}
}
//添加某个学生
public static void addStudent(ArrayList<Student>a){
Scanner in=new Scanner(System.in);
System.out.println("请输入学号");
String num=in.next();
System.out.println("请输入姓名");
String name=in.next();
System.out.println("请输入年龄");
String age=in.next();
System.out.println("请输入家庭居住地");
String id=in.next();
Student stu=new Student(num,name,age,id);
a.add(stu);
System.out.println("添加成功");
}
//删除某个学生
public static void deleteStudent(ArrayList<Student>a){
System.out.println("请输入您要删除的学号");
Scanner in=new Scanner(System.in);
String num=in.next();
for(int i=0;i<a.size();i++){
Student stu= a.get(i);
if(stu.getNum().equals(num))
a.remove(i);
}
System.out.println("删除成功");
}
//修改某个学生信息
public static void removeStudent(ArrayList<Student>a){
Scanner in=new Scanner(System.in);
System.out.println("请输入要修改的学生的学号");
String num=in.next();
System.out.println("请输入新姓名");
String name= in.next();
System.out.println("请重新输入年龄");
String age= in.next();
System.out.println("请重新输入家庭居住地");
String id= in.next();
Student s=new Student();
s.setNum(num);
s.setName(name);
s.setAge(age);
s.setId(id);
for(int i=0;i<a.size();i++){
Student stu= a.get(i);
if(stu.getNum().equals(num))
a.set(i,s);
}
}
//查看所有学生信息
public static void findStudent(ArrayList<Student>a){
System.out.println("学号 姓名 年龄 居住地址");
for(int i=0;i<a.size();i++) {
Student stu = a.get(i);
System.out.println(stu.getNum()+" "+stu.getName()+" "+stu.getAge()+" "+stu.getId());
}
}
}
边栏推荐
- 来自“飞人”乔丹的启示!奥尼尔开启的另一个“赛场”
- The project connects with Alipay payment, and the intranet penetration realizes the monitoring of asynchronous callback notification of successful payment of Alipay
- 使用ngrok做内网穿透
- How does the TCP server handle multiple client connections on one port (one-to-one or one to many)
- Interface and abstract class / method learning demo
- SSM framework integration
- How to store the startprocessinstancebykey method in acticiti in the variable table
- 整合SSM
- 2、 MySQL advanced
- 二、MySQL高级
猜你喜欢
![[Niuke discussion area] Chapter 7: building safe and efficient enterprise services](/img/62/2b170e8dd5034708aebc6df0bc2b06.png)
[Niuke discussion area] Chapter 7: building safe and efficient enterprise services

一、MySQL基础

数据库设计——关系数据理论(超详细)

JVM Part 1: memory and garbage collection part 8 - runtime data area - Method area

来自“飞人”乔丹的启示!奥尼尔开启的另一个“赛场”

素数筛选(埃氏筛法,区间筛法,欧拉筛法)

Svn usage details

Raspberry pie RTMP streaming local camera image
![[acwing] solution to the 61st weekly match](/img/31/765f4ce9f779e8093668e7606e0198.png)
[acwing] solution to the 61st weekly match

JVM上篇:内存与垃圾回收篇十--运行时数据区-直接内存
随机推荐
String class
集合框架的使用
Explore the mysteries of the security, intelligence and performance of the universal altek platform!
Constraints of MySQL table
Counting Nodes in a Binary Search Tree
34. Analyze flexible.js
How does the TCP server handle multiple client connections on one port (one-to-one or one to many)
feign调用丢失请求头问题解决及原理分析
Scientific Computing Library -- Matplotlib
Mysql表的约束
Svn usage details
Deep Qt5 signal slot new syntax
B1030 完美数列
Differences among left join, inner join and right join
Inspiration from "flying man" Jordan! Another "arena" opened by O'Neill
Shell course summary
支付流程如何测试?
数据库设计——关系数据理论(超详细)
35.滚动 scroll
Interface and abstract class / method learning demo