public class Main {
public static void main(String[] args){
MainPage mp=new MainPage();
mp.Read();
}
}
=====================================================
Student方法:
package studentControlSystem;
public class Student {
private String name;
private int age;
public Student(){}
public Student(String name,int age){
this.name=name;
this.age=age;
}
public void setName(String name){
this.name=name;
}
public String getName(){
return name;
}
public void setAge(int age){
this.age=age;
}
public int getAge(){
return age;
}
}
=======================================================
页面显示方法:
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MainPage {
private ArrayList<Student> arrayStudent;
private Scanner scanner;
//主页面屏幕显示
public MainPage(){
arrayStudent=new ArrayList<>();
scanner=new Scanner(System.in);
}
//读取功能输入
public void Read(){
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("请开始你的表演:");
//输入的序号
String input = scanner.next();
//合理性校验
if (Check(input)){
continue;
}
//String转化为整形
switch (Integer.parseInt(input)){
case 1:
getAllStudent();
break;
case 2:
addStudent();
break;
case 3:
deleteStudent();
break;
case 4:
setStudent();
break;
case 5:
System.exit(0);
default:
}
}
}
//菜单合理性校验
private boolean Check(String input){
//使用正则表达式只允许1-5
Pattern p=Pattern.compile("[12345]");
Matcher m=p.matcher(input);
//添加学生
public void addStudent(){
System.out.println("请输入学生的名字:");
String name = scanner.next();
int age=CheckAge();
arrayStudent.add(new Student(name, age));
Back();
}
//删除学生
public void deleteStudent(){
int delete=CheckIndex();
String deleteName=arrayStudent.remove(delete).getName();
System.out.println("您删除的是学生"+deleteName);
Back();
}
//修改学生
public void setStudent(){
int set=CheckIndex();
System.out.println("请输入学生的名字:");
String name=scanner.next();
int age=CheckAge();
arrayStudent.set(set,new Student(name,age));
Back();
}
}
==============================================
见笑了 作者: 小浙姐姐 时间: 2018-5-15 12:12
学生管理系统哈哈,自己默出来的吗?