JavaSE第一阶段项目_学生管理系统
1.项目介绍
此项目是JavaSE 第一阶段的项目, 主要完成学生对象在数组中的增删改查, 大家可以在此项目中发挥自己的想象力做完善, 添加其他功能等操作, 但是重点仍然是咱们前9 个模块的知识点
2.项目展示
2.1.添加功能
2.2.查看功能
2.3.修改功能
2.4.删除功能
2.5.退出功能
3.功能实现
3.1.JavaBean_Student
public class Student {
private int id;
private String name;
private int age;
private String sex;
public Student ( ) {
}
public Student ( int id, String name, int age, String sex) {
this . id = id;
this . name = name;
this . age = age;
this . sex = sex;
}
public int getId ( ) {
return id;
}
public void setId ( int 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;
}
public String getSex ( ) {
return sex;
}
public void setSex ( String sex) {
this . sex = sex;
}
}
3.2.启动项目_Test01
public class Test01 {
public static void main ( String [ ] args) {
new StudentView ( ) . start ( ) ;
}
}
3.3.操作页面_StudentView
public class StudentView {
Scanner sc = new Scanner ( System . in) ;
Student [ ] students = new Student [ 50 ] ;
int count = 0 ;
Student [ ] newStudents = new Student [ students. length- 1 ] ;
public void start ( ) {
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 ( "请选择(1-5):" ) ;
int num = sc. nextInt ( ) ;
System . out. println ( "--------------------------------" ) ;
switch ( num) {
case 1 :
addStudent ( ) ;
break ;
case 2 :
updateStudent ( ) ;
break ;
case 3 :
deleteStudent ( ) ;
break ;
case 4 :
findAllStudent ( ) ;
break ;
case 5 :
System . out. println ( "退出功能" ) ;
break ;
}
}
}
private void findAllStudent ( ) {
System . out. println ( "查看功能" ) ;
}
private void deleteStudent ( ) {
System . out. println ( "删除功能" ) ;
}
private void updateStudent ( ) {
System . out. println ( "修改功能" ) ;
}
private void addStudent ( ) {
System . out. println ( "添加功能" ) ;
}
}
3.4.工具类_ArrayUtils
public class ArrayUtils {
private ArrayUtils ( ) {
}
public static int findIndexById ( Student [ ] students, int id, int count) {
for ( int i = 0 ; i < count; i++ ) {
if ( id== students[ i] . getId ( ) ) {
return i;
}
}
return - 1 ;
}
}
3.5.添加功能_addStudent
private void addStudent ( ) {
System . out. println ( "请您输入学生学号:" ) ;
int id = sc. nextInt ( ) ;
System . out. println ( "请您输入学生姓名:" ) ;
String name = sc. next ( ) ;
System . out. println ( "请您输入学生年龄:" ) ;
int age = sc. nextInt ( ) ;
System . out. println ( "请您输入学生性别:" ) ;
String sex = sc. next ( ) ;
Student student = new Student ( id, name, age, sex) ;
students[ count] = student;
count++ ;
System . out. println ( "添加成功!!!" ) ;
}
3.6.查看功能_findAllStudent
private void findAllStudent ( ) {
System . out. println ( "学号" + "\t" + "姓名" + "\t" + "年龄" + "\t" + "性别" ) ;
for ( int j = 0 ; j < count- 1 ; j++ ) {
for ( int i = 0 ; i < count- 1 - j; i++ ) {
if ( students[ i] . getId ( ) > students[ i+ 1 ] . getId ( ) ) {
Student temp = students[ i] ;
students[ i] = students[ i+ 1 ] ;
students[ i+ 1 ] = temp;
}
}
}
if ( count== 0 ) {
System . out. println ( "对不起,现在班级没有学生,待开班........." ) ;
} else {
for ( int i = 0 ; i < count; i++ ) {
System . out. println ( students[ i] . getId ( ) + "\t" + students[ i] . getName ( ) + "\t" + students[ i] . getAge ( ) + "\t" + students[ i] . getSex ( ) ) ;
}
}
}
3.7.修改功能_updateStudent
private void updateStudent ( ) {
System . out. println ( "请您输入要修改的学生学号:" ) ;
int id = sc. nextInt ( ) ;
int updateIndex = ArrayUtils . findIndexById ( students, id, count) ;
System . out. println ( "请您输入学生姓名:" ) ;
String name = sc. next ( ) ;
System . out. println ( "请您输入学生年龄:" ) ;
int age = sc. nextInt ( ) ;
System . out. println ( "请您输入学生性别:" ) ;
String sex = sc. next ( ) ;
Student student = new Student ( id, name, age, sex) ;
students[ updateIndex] = student;
System . out. println ( "修改成功!!!" ) ;
}
3.8.删除功能_deleteStudent
private void deleteStudent ( ) {
System . out. println ( "请您输入要删除的学生学号:" ) ;
int id = sc. nextInt ( ) ;
int removeIndex = ArrayUtils . findIndexById ( students, id, count) ;
System . arraycopy ( students, 0 , newStudents, 0 , removeIndex) ;
System . arraycopy ( students, removeIndex+ 1 , newStudents, removeIndex, students. length- removeIndex- 1 ) ;
students = newStudents;
count-- ;
System . out. println ( "删除成功" ) ;
}
3.9.退出功能_switch
case 5 :
System . out. println ( "是否退出?按0为退出/按9为取消" ) ;
int key = sc. nextInt ( ) ;
if ( key == 0 ) {
System . out. println ( "再见,欢迎再来" ) ;
return ;
} else if ( key == 9 ) {
break ;
}