Java简单学生管理系统
程序员文章站
2022-10-18 18:01:29
Java简单学生管理系统这个不需要手动输入,笔记记录//student`public class student(){ private String id;//学号 private String name;//姓名 private int age;//年龄public String getId() { return id;}public void setId(String id) { this.id = id;}public String getName()...
Java简单学生管理系统
这个不需要手动输入,笔记记录
//student`
public class student(){
private String id;//学号
private String name;//姓名
private int age;//年龄
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public String toString() {
return "Student{" +
"id='" + id + '\'' +
", name='" + name + '\'' +
", age=" + age +
'}';
}
public Student(String id, String name, int age) {
this.id = id;
this.name = name;
this.age = age;
}
}
//studentManger
public class StudentManager {
Student[] stus=new Student[20];//声明数组
static int count=0;//学生数量
public void add(Student stu){
stus[count] =stu;
count++;
}
//查一条数据
public void findByid(String id){
for (int i = 0; i < stus.length; i++) {
Student stu=this.stus[i];
if (stu.getId().equals(id)){
System.out.println(stu);
}
}
}
//查询所有
public void findAll(){
for (int i = 0; i < count; i++) {
System.out.println(stus[i]);
}
}
//修改
public void udp(String id,Student student){
for (int i = 0; i < stus.length; i++) {
Student stu=this.stus[i];
if (stu.getId().equals(id)){
stus[i]=student;
findAll();
}
}
}
//删除
public void del(String id){
for (int i = 0; i < count; i++) {
if (stus[i].getId()==id){
for (int j = i; j <stus.length-1 ; j++) {
if (stus[j]!=null){
stus[j]=stus[j+1];
}
}
count--;
}
}
}
public static void main(String[] args) {
//添加数据
StudentManager sm=new StudentManager();
Student s1=new Student("01","tom",20);
sm.add(s1);
Student s2=new Student("02","lili",19);
sm.add(s2);
//Student s3=new Student("02","lucy",19);修改数据
//sm.udp("02",s3);
// sm.del("02");删除数据
//sm.findByid("02");查找一个数据
sm.findAll();//查询所有
}
}
添加数据的效果图
需要实现那个功能就调用哪个方法。
本文地址:https://blog.csdn.net/LN18303855296/article/details/107354676