Student
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
*<P>Project:vue01 - Student
*<P>Powered by alay On 2022-10-08 14:21:46
*
*@author alay
*@version 1.0
*@since 17
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Student {
private int sid;
private String sname;
private String sgender;
private int sage;
private String address;
}
StudentManager
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
*<P>Project:vue01 - StudentManager
*<P>Powered by alay On 2022-10-08 14:18:21
*
*@author alay
*@version 1.0
*@since 17
*/
public class StudentManager {
public static void main(String[] args) {
//建立集合
List<Student> sm=new ArrayList<>();
//循环语句
menu:
while(true){
//建立键盘输出对象
Scanner sc=new Scanner(System.in);
System.out.println(Util.center("学生管理系统",50,"*"));
System.out.println(Util.center("1.添加学生 ",50," "));
System.out.println(Util.center("2.删除学生 ",50," "));
System.out.println(Util.center("3.修改学生 ",50," "));
System.out.println(Util.center("4.查看所有学生",50," "));
System.out.println(Util.center("5.退出 ",50," "));
System.out.print("请输入[1-5]:");
int index = sc.nextInt();
switch(index){
case 1:
Util.add(sm);
System.out.println("添加");
break;
case 2:
Util.delete(sm);
System.out.println("删除");
break;
case 3:
Util.revise(sm);
System.out.println("修改");
break;
case 4:
Util.printAll(sm);
System.out.println("查看");
break;
default:
System.out.println("系统退出");
break menu;
}
}
}
}
Util
import java.util.List;
import java.util.Scanner;
/**
*<P>Project:vue01 - Util
*<P>Powered by alay On 2022-10-08 14:39:28
*
*@author alay
*@version 1.0
*@since 17
*/
public class Util {
public static void add(List<Student> sm){
Scanner sc=new Scanner(System.in);
Student st=new Student();
System.out.print("请输入学生学号,是一个整数:");
st.setSid(sc.nextInt());
System.out.print("请输入姓名:");
st.setSname(sc.next());
System.out.print("请输入性别[男|女]:");
st.setSgender(sc.next());
System.out.print("请输入年龄:");
st.setSage(sc.nextInt());
System.out.print("请输入家庭地址:");
st.setAddress(sc.next());
sm.add(st);
try{
System.out.println("保存...");
Thread.sleep(1000);
}catch(Exception e){
e.printStackTrace();
}
System.out.printf("学生:%s,信息录入保存成功!!!%n",st.getSname());
}
public static void printAll(List<Student> sm) {
System.out.printf("%n%s %s %s%n%n","学号","姓名","家庭地址");
sm.forEach(s->{
System.out.printf("%n%d %s %s%n%n",s.getSid(),s.getSname(),s.getAddress());
});
System.out.printf("共有学生为:%d%n",sm.size());
}
public static void delete(List<Student> sm) {
System.out.println(Util.center("删除",20,"*"));
Scanner sc=new Scanner(System.in);
System.out.print("请输入删除的学生学号:");
int sno =sc.nextInt();
boolean f=false;
for(int i=0;1<sm.size();i++){
Student st=sm.get(i);
if(st.getSid()==sno){
f=true;
sm.remove(st);
}
}
if(f){
System.out.println("删除成功:%s%n");
}else{
System.out.println("删除失败,请检查您的学号...");
}
System.out.println();
}
static String center(String str, int length, String ch) {
int size=(length-str.length())/2;
return ch.repeat(size).concat(str).concat(ch.repeat(size));
}
public static void revise(List<Student> sm) {
}
}