JAVA学生管理系统
JAVA学生管理系统
一、学生类
public class Student
{
private String name;
private String age;
private String id;
private String address;
Student()
{
}
Student(String name,String age,String id,String address)
{
this.name = name;
this.age = age;
this.id = id;
this.address = address;
}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void setAge(String age)
{
this.age = age;
}
public String getAge()
{
return age;
}
public void setId(String id)
{
this.id = id;
}
public String getId()
{
return id;
}
public void setAddress(String address)
{
this.address = address;
}
public String getAddress()
{
return address;
}
}
二、主函数
import java.util.ArrayList;
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
ArrayListStudent arrayList = new ArrayList();
boolean flag = true;
Scanner scanner = new Scanner(System.in);
int choose = -1;
while (flag)
{
show();
choose = scanner.nextInt();
switch (choose)
{
case 1:
addStudent(arrayList);
break;
case 2:
deleteStudent(arrayList);
break;
case 3:
alterStudent(arrayList);
break;
case 4:
showAllStudent(arrayList);
break;
case 5:
System.out.println(欢迎您下次使用!);
flag = false;
break;
}
}
}
public static void show()
{
System.out.println(--------欢迎来到学生管理系统-------- + n +
1 添加学生 + n +
2 删除学生 + n +
3 修改学生 + n +
4 查看学生 + n +
5 退出系统 + n +
请输入您的选择:);
}
public static void addStudent(ArrayListStudent arrayList)
{
Scanner scanner = new Scanner(System.in);
Student student = new Student();
System.out.print(请输入学生姓名:);
student.setName(scanner.nextLine());
System.out.print(请输入学生年龄:);
student.setAge(scanner.nextLine());
System.out.print(请输入学生学号:);
student.setId(scanner.nextLine());
System.out.print(请输入学生地址:);
student.setAddress(scanner.nextLine());
arrayList.add(student);
System.out.println(添加学生成功!);
}
public static void deleteStudent(ArrayListStudent arrayList)
{
System.out.print(请输入所要删除学生的学号:);
Scanner scanner = new Scanner(System.in);
String id = scanner.nextLine();
for (int i = 0; iarrayList.size(); i++)
{
if (arrayList.get(i).getId().equals(id))
{
arrayList.remove(i);
System.out.println(删除学生成功!);
break;
}
}
}
public static void alterStudent(ArrayListStudent arrayList)
{
System.out.print(请输入所要修改学生的学号:);
Scanner scanner = new Scanner(System.in);
String id = scanner.nextLine();
for (int i = 0; iarrayList.size(); i++)
{
if (arrayList.get(i).getId().equals(id))
{
Student student = new Student();
System.out.print(请输入学生姓名:);
student.setName(scanner.nextLine());
System.out.print(请输入学生年龄:);
student.setAge(scanner.nextLine());
System.out.print(请输入学生学号:);
student.setId(scanner.nextLine());
System.out.print(请输入学生地址:);
student.setAddress(scanner.nextLine());
arrayList.set(i,student);
System.out.println(修改学生成功!);
break;
}
}
}
public static void showAllStudent(ArrayListStudent arrayList)
{
System.out.println(姓名t年龄t学号t地址);
for (int i = 0; iarrayList.size(); i++)
{
System.out.println(arrayList.get(i).getName() + t + arrayList.get(i).getAge() + t + arrayList.get(i).getId() + t + arrayList.get(i).getAddress());
}
}
}
(JAVA学生管理系统)宝,都看到这里了你确定不收藏一下??