java学生管理系统(简单版)

article/2025/9/28 11:00:44

简单实现学生信息添加、删除,修改、查询功能。根据需求,创建一个学生类和学生管理类,用容器存储学生信息,这里用到ArrayList<E>(ArrayList类是一个可动态修改的数组,使用之前需要导包import java.util.ArrayList;)

创建集合对象

ArrayList<E> 名 = new ArrayList<E>( );   {<E>是一种特殊的数据类型,泛型}

例:ArrayList<String>  students = new ArrayList<String>( );

其中有如下方法:

add(element)将指定元素追加到集合末尾

add (int index,element) 在指定索引下添加元素

remove(element)删除指定元素

remove (int index)删除指定索引下的元素

set(int index,element)修改指定索引下的元素

get(int index)返回索引下的元素

size() 返回元素个数 

一、建立学生类

学生类中应包含有学生姓名、年龄、学号、籍贯。

public class Student {private String name;private String age;private String id;private String adress;public Student() {}public Student(String name, String age, String id, String adress) {this.name = name;this.age = age;this.id = id;this.adress = adress;}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;}public String getAdress() {return adress;}public void setAdress(String adress) {this.adress = adress;}
}

二、创建学生管理类

设计初始界面

六种功能选择用switch语句实现 

用方法实现增、删、改、查功能

添加学生信息的方法

public static void  adds(ArrayList<Student> student) {

 Scanner sc = new Scanner(System.in);System.out.println("请输入学生姓名:");String name = sc.nextLine();System.out.println("请输入学生年龄:");String age =sc.nextLine();System.out.println("请输入学生学号:");String id =sc.nextLine();System.out.println("请输入学生地址:");String adress =sc.nextLine();Student students = new Student();//创建学生对象students.setName(name);  students.setAge(age);students.setId(id);students.setAdress(adress); //将输入的值赋给学生对象的成员变量student.add(students);      //讲学生对象添加到集合中System.out.println("添加学生信息成功");
}

删除学生信息的方法

public static void removes(ArrayList<Student> student){Scanner sc = new Scanner(System.in);System.out.println("请输入要删除学生的学号:");String id = sc.nextLine();ugai用for循环遍历student集合找到与输入学号相同的学号从而找到对应学生类对象再用remove()方法删除 */for(int i = 0;i < student.size();i++){Student s = student.get(i);
//epuals()方法将字符串与指定对象进行比较,返回是否相同;if(s.getId().equals(id)){System.out.println("删除后无法恢复,是否要继续删除");System.out.print("1:是\n2:否\n");int a = sc.nextInt();if(a==1) {student.remove(i);break;}else{break;}}}
}

修改学生信息方法

public static void setOne(ArrayList<Student> student){Scanner sc = new Scanner(System.in);System.out.println("请输入所要修改学生的学号");String sid = sc.nextLine();System.out.println("请输入新的学生姓名:");String name = sc.nextLine();System.out.println("请输入新的学生年龄:");String age =sc.nextLine();System.out.println("请输入新的学生学号:");String id =sc.nextLine();System.out.println("请输入新的学生地址:");String adress =sc.nextLine();Student s = new Student();s.setName(name);s.setAge(age);s.setId(id);s.setAdress(adress);//输入要修改的信息并把它赋值给新的学生类对象for(int i = 0;i < student.size();i++){Student a = student.get(i);if(a.getId().equals(sid)){student.set(i,s);
/*通过equals()方法找到对应学生类对象再用set(int index,element)方法将旧的学生类对象修改为新的*/break;}System.out.println("修改学生信息成功");}}

查询学生信息方法

public static void printAll(ArrayList<Student> student){Scanner sc = new Scanner(System.in);
//先做判断,集合中是否有信息if(student.size()==0){System.out.println("无学生信息,请先添加学生信息");System.out.println("请选择是否添加学生信息:");System.out.println("1:添加学生信息\n2:退出\n");int n = sc.nextInt();switch (n){case 1:adds(student);break;case 2:System.exit(0);break;default:System.out.println("你的选择有误,请选择已存在的业务");}}else{//遍历集合System.out.println("学生姓名\t年龄\t学号\t地址\t");for(int i = 0;i < student.size();i++) {Student s = student.get(i);System.out.println(s.getName() + "\t" + s.getAge() + "岁\t" + s.getId() + "\t" + s.getAdress() + "\t");}}
}

学生管理类代码如下:

import java.util.ArrayList;
import java.util.Scanner;
public class StudentManage {public static void main(String[] args) {ArrayList<Student> student= new ArrayList<Student>();Scanner sc = new Scanner(System.in);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("| 6:退出管理系统                   |");System.out.println("--------------------------------");System.out.println("请选择要进行的业务:");int n = sc.nextInt();switch (n) {case 1:System.out.println("增加学生信息");adds(student);break;case 2:removes(student);break;case 3:setOne(student);break;case 4:printOne(student);break;case 5:printAll(student);break;case 6:System.exit(0);break;default:System.out.println("你的选择有误,请选择现有的业务");}}}//增加学生信息方法public static void adds(ArrayList<Student> student){Scanner sc = new Scanner(System.in);System.out.println("请输入学生姓名:");String name = sc.nextLine();System.out.println("请输入学生年龄:");String age =sc.nextLine();System.out.println("请输入学生学号:");String id =sc.nextLine();System.out.println("请输入学生地址:");String adress =sc.nextLine();Student students = new Student();students.setName(name);students.setAge(age);students.setId(id);students.setAdress(adress);student.add(students);System.out.println("添加学生信息成功");}//删除学生信息public static void removes(ArrayList<Student> student){Scanner sc = new Scanner(System.in);System.out.println("请输入要删除学生的学号:");String id = sc.nextLine();for(int i = 0;i < student.size();i++){Student s = student.get(i);if(s.getId().equals(id)){System.out.println("删除后无法恢复,时候要继续删除");System.out.print("1:是\n2:否\n");int a = sc.nextInt();if(a==1) {student.remove(i);break;}else{break;}}}}//修改学生信息public static void setOne(ArrayList<Student> student){Scanner sc = new Scanner(System.in);System.out.println("请输入所要修改学生的学号");String sid = sc.nextLine();System.out.println("请输入新的学生姓名:");String name = sc.nextLine();System.out.println("请输入新的学生年龄:");String age =sc.nextLine();System.out.println("请输入新的学生学号:");String id =sc.nextLine();System.out.println("请输入新的学生地址:");String adress =sc.nextLine();Student s = new Student();s.setName(name);s.setAge(age);s.setId(id);s.setAdress(adress);for(int i = 0;i < student.size();i++){Student a = student.get(i);if(a.getId().equals(sid)){student.set(i,s);break;}System.out.println("修改学生信息成功");}}//查找学生信息public static void printOne(ArrayList<Student> student){Scanner sc = new Scanner(System.in);System.out.println("请选择所要查找学生的学号");String id = sc.nextLine();for(int i = 0; i < student.size();i++){Student s = student.get(i);if(s.getId().equals(id)){System.out.println("学生姓名\t年龄\t学号\t地址\t");System.out.println(s.getName()+"\t"+s.getAge()+"岁\t"+s.getId()+"\t"+s.getAdress()+"\t");}}}//查找所有学生信息public static void printAll(ArrayList<Student> student){Scanner sc = new Scanner(System.in);if(student.size()==0){System.out.println("无学生信息,请先添加学生信息");System.out.println("请选择是否添加学生信息:");System.out.println("1:添加学生信息\n2:退出\n");int n = sc.nextInt();switch (n){case 1:adds(student);break;case 2:System.exit(0);break;default:System.out.println("你的选择有误,请选择已存在的业务");}}else{System.out.println("学生姓名\t年龄\t学号\t地址\t");for(int i = 0;i < student.size();i++) {Student s = student.get(i);System.out.println(s.getName() + "\t" + s.getAge() + "岁\t" + s.getId() + "\t" + s.getAdress() + "\t");}}}
}


http://chatgpt.dhexx.cn/article/GVTXxRib.shtml

相关文章

Keil打开工程时,解决“Loading PDSC Debug Description Failed”错误

网上搜到一个方法是&#xff0c;把Keil.STM32Lxxx_DFP.pdsc文件中&#xff0c;删除行“Message(2, "Not a genuine ST Device! Abort connection.");”&#xff0c; 这个方法属于掩耳盗铃&#xff0c;只是不让他弹出错误而已。 正确的解决方法是&#xff0c;安装与…

STM32 Keil新建工程报错“Loading PDSC Debug Description Failed for STMicroelectronics STM32Lxxxxxxx”

在使用STM32L0xx系列和STM32L4xx系列的单片机时都遇到了打开keil工程报“Loading PDSC Debug Description Failed for STMicroelectronics STM32Lxxxxxxx”错误的问题&#xff0c;具体现象和解决方法如下图文所示&#xff1a; 找到keil的Build Output窗口提示的File路径&#x…

解决Keil安装Pack包的“Loading PDSC Debug Description Failed”错误

vision Loading PDSC Debug Description failed for STMicroelectronics STM32F103ZE Disabling usage of PDSC Debug DescriptionSee Build Output for details. connection.");" 具体的错误信息&#xff0c;可以在Build Output中查看&#xff0c;如下图所示。这个…

Disabling usage of PDSC Debug Description

STM32 Keil新建工程报错“Loading PDSC Debug Description Failed for STMicroelectronics STM32Lxxxxxxx” 在使用STM32L0xx系列和STM32L4xx系列的单片机时都遇到了打开keil工程报“Loading PDSC Debug Description Failed for STMicroelectronics STM32Lxxxxxxx”错误的问题…

Loading PDSC Debug Description failed for STMicroelectronics STM32F103ZF Disabling usage of PDSC Deb

用 STM32F103 软件仿真 &#xff0c;还需要下载安装 STM32F103 pack 文件&#xff0c;如果在 MDK 中下载较慢&#xff0c;也可以点击此处下载&#xff0c;下载后双击安装即可。 当Keil新建或者打开工程出现“ Loading PDSC Debug Description failed for STMicroelectronics S…

PD协议

最近在搞PD充电部分&#xff0c;资料记录下&#xff0c;以前搞了很多项目 也记录了很多文档资料&#xff0c;不过感觉平时喜欢乱打开网站&#xff0c;而那些word文档 经常被放在一个文件夹中&#xff0c;一放就好几年。所以开始在csdn记录自己整理的东西。 定义&#xff1a; U…

N32G45导入芯片包出现Cannot install Pack Nationstech.N32G45x_DFP.1.0.4: Cannot find PDSC file at root direct

Cannot install Pack Nationstech.N32G45x_DFP.1.0.4: Cannot find PDSC file at root directory of Pack archive 最近训练营要求用到国产芯片N32G45X系列的芯片&#xff0c;但是在keil中导入芯片包时出现了以下问题&#xff1a; Cannot install Pack Nationstech.N32G45x_DF…

SDP简介

1 概述 SDP制订的目的是描述多媒体会话&#xff0c;如会话通知、会话邀请或其他发起多媒体会话的形式。 SDP是纯粹的会话的描述格式而不是一个传输协议。它可以使用不同的传输协议&#xff0c;包括会话通知协议&#xff08;SAP&#xff09;、会话初始协议&#xff08;SIP&…

MDK5/KeiluVsion5安装报错“Download of PDSC index file failed”

一、原因一分析&#xff1a; 1.先从字面分析&#xff1a;Download of PDSC index file failed中文意思是PDSC这个索引文件下载错误。首先我们要知道&#xff0c;刚开始安装软件或当你进入Pack Installer界面时&#xff0c;软件会从Keil官网更新下载keil软件所需要的一些芯片包…

Keil5 “Loading PDSC Debug Description Failed for STMicroelectronics STM32Hxxxxxxx”解决办法

最近在学习STM32H750&#xff0c;但是在创建工程的时候就发现了一个问题&#xff0c;如图所示&#xff1a; 虽然不清楚这个问题是否会影响后面编译和烧录&#xff0c;但是感觉有这种警告还是不爽的&#xff0c;所以这里记录一下。 按照这个路径&#xff0c;找到这个pdsc后缀的…

打开Keil.STM32F4xx_DFP.2.13.0提示Cannot copy PDSC file to Download

打开Keil.STM32F4xx_DFP.2.13.0提示Cannot copy PDSC file to “Download” folder 一、问题&#xff1a; keil5安装好后直接安装添加.pack时提示Cannot copy PDSC file to “Download” folder。以为是版本问题或者keil4等在同一个盘中&#xff0c;下了好几个版本又分盘安装&…

sdp详解

SDP文件解析 一、SDP协议介绍 SDP 完全是一种会话描述格式 ― 它不属于传输协议 ― 它只使用不同的适当的传输协议&#xff0c;包括会话通知协议&#xff08;SAP&#xff09;、会话初始协议&#xff08;SIP&#xff09;、实时流协议&#xff08;RTSP&#xff09;、MIME 扩展协…

STM32烧录错误【PDSC: Sequence Execution failed error-Debug access failed - cannot read address 0xE00FFFE】

背景&#xff1a;一开始可以正常烧录&#xff0c;由于写了个文件的代码&#xff0c;编译正常&#xff0c;但是load的时候突然报错……后来换成了本来可以正常烧录的工程发现依然没办法烧录&#xff0c;遂明白自己把板子搞坏了…… 错误提示&#xff1a; Sequence : DebugDevic…

STM32踩坑:Keil 安装好后创建项目 Loading PDSC Debug Description failed for...

Keil 安装好后创建项目警告 Loading PDSC Debug Description failed for… 昨天重新装了一下系统&#xff0c;重新安装了一次 Keil&#xff0c;新建项目的时候报了一个错&#xff0c;如下图&#xff1a; 点击确定后&#xff0c;在下方输出框中可见下图&#xff1a; 按照第一…

STM32Cube安装固件库出现 invalid zip file or missing expected pdsc file within pack root directory

意思是压缩包无效或者缺少pdsc文件 再下一次压缩包&#xff0c;是否压缩包出现问题 还是这样就看看这里 看这里软件可安装固件库版本&#xff0c;假设我要安装 1.27.0版本就会出现 invalid zip file or missing expected pdsc file within pack root directory 这里需要更新…

PDSCH 相关

1 PDSCH信道处理过程 见PDSCH 处理流程整理https://blog.csdn.net/fanzy_edu/article/details/122469006 在5GNR中&#xff0c;MAC层最多向物理层传输2个TB传输块&#xff0c;且2个TB块只适用于空分复用超过4层的情况。若当前空分复用不超过4层&#xff08;含4层&#xff09;&…

打开Keil.STM32F4xx_DFP.2.13.0提示Cannot copy PDSC file to “Download“

打开Keil.STM32F4xx_DFP.2.13.0提示Cannot copy PDSC file to “Download” folder 一、问题&#xff1a; keil5安装好后直接安装添加.pack时提示Cannot copy PDSC file to “Download” folder。以为是版本问题或者keil4等在同一个盘中&#xff0c;下了好几个版本又分盘安装…

KEIL出现Loading PDSC Debug Description failed解决办法

症状 解决办法 一、找到对应库路径 二、取消PDSC文件只读属性 三、查找“Message(2,“Not a genuine ST Device! Abort connection”);”并删除&#xff0c;保存 四、恢复只读属性 完~~~

问题记录:MDK提示 Loading PDSC Debug Descriptionfailed 解决方法

在使用野火STM32F429挑战者_V2开发板时&#xff0c;&#xff0c;使用MDK打开工程后&#xff0c;每次打开都会弹出错误提示。 在浏览网上资料后&#xff0c;在这位兄弟的博文中找到了解决方法。 在Keil ARM的安装目录下找到D:\Keil_v5\ARM\Pack\Keil\STM32F4xx_DFP\2.14.0此路径…

keil报错解决:Loading PDSC Debug Description failed for STMicroelectronics STM32Fxxxxxxx

一、错误现象&#xff1a; 每次打开相应工程都会出现如下错误提示框&#xff1a; Loading PDSC Debug Description failed for STMicroelectronics STM32F072C8Tx Disabling usage of PDSC Debug Description. See Build Output for details. 二、错误分析&#xff1a; Fil…