package StudentGuanLi;
/*类 ---
Student.java
学生变量 -- getter setter
Login.java
login方法 完成登录操作
StudentManager.java
init();
在此方法中完成功能选择
1.查看学生信息
2.添加学生
3删除学生
4改变学生信息
6.退出系统
searchStudent();
addStudent();
delStudentById();
changeStudentById();
searchStudentById();
学生管理的方法
Main.java
程序的入口
对象 ---
Student对象 -- 保存学生信息
*/
public class Main {
public static void main(String[] args) {
Login lo=new Login();
lo.DenLu();//在主方法调用DenLu();这个方法
}
}
package StudentGuanLi;
import java.util.Scanner;
public class Login {
public void DenLu(){
int i = 2;
String name = "q";
String password = "123";
Scanner sc = new Scanner(System.in);
System.out.print("请输入您的用户名:");
String name_in = sc.next();
System.out.print("请输入您的密码:");
String password_in = sc.next();
for (int k = 1; k <= 3; k++) {
if (name_in.equals(name) && password_in.equals(password)) {
System.out.println("登录成功");
StudentManager.init();//进入StudentManager.init();这个方法
break;
} else {
System.out.println("用户名或密码错误,你还有" + i + "次输入机会");
i--;
break;
}
}
}
}
package StudentGuanLi;
import java.util.Scanner;
public class StudentManager {
static Student stu[]=new Student[3];
static String[] st= {"张三男20120","李四男20121","王六男20122"};
public static void init() {
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("6.退出学生信息");
System.out.println(".....请输入你的选择.....");
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
switch(a) {
case 1:
searchStudent(); break;
case 2:
addStudent();break;
case 3:
delStudentById();break;
case 4:
changeStudentById();break;
case 5: all(); break;
case 6:System.out.print("退出学生信息");
break;
}
}
//查看学生信息
public static void searchStudent() {
for(int i=0;i<st.length;i++) {
Scanner sc=new Scanner(System.in);
System.out.println("请输入" + " 学生姓名:"+"学生性别:"+"学生年龄:"+"学生学号:");
String a=sc.next();
if(a.equals(stu[i])) {
System.out.print("此学生信息"+stu[i]);
break;
}
else {System.out.print("查无此人");}
}
StudentManager.init();
}
//增加学生信息
public static Student[] addStudent() {
System.out.println("学生信息");
Student[] stus = new Student[3];
Scanner sc=new Scanner(System.in);
for (int i = 0; i < stu.length; i++) {
System.out.println("请输入学生姓名:");
String Stuname = sc.next();
System.out.println("请输入学生性别:");
String gender= sc.next();
System.out.println("请输入学生年龄:");
int age = sc.nextInt();
System.out.println("请输入学生学号:");
int StuNum = sc.nextInt();
// 将输入的学生信息保存在学生对象中
Student st=new Student( Stuname,gender,age,StuNum);
// 将学生对象放入学生数组中
stu[i] = st;
StudentManager.init();
}
return stu;
}
//删除学生信息
public static boolean delStudentById() {
int n = 3;
System.out.println("请输入学号");
Scanner sc=new Scanner(System.in);
String a=sc.next();
for(int i=0;i<n;i++) {
if(st[i].contains(a)) {
st[i]="0";
StudentManager.init();
return true;
}
}
return false;
}//更改学生信息
public static void changeStudentById() {
System.out.println("修改:请输入现在学号");
Scanner sc=new Scanner(System.in);
String idold= sc.nextLine();
System.out.println("修改:请输入修改后学号");
String idnew = sc.nextLine();
for (int i = 0; i < st.length; i++) {
if(st[i].contains(idold)) {
String[] name = st[i].split(idold);
st[i]=name[0]+idnew;
System.out.println(st[i]);
StudentManager.init();
}
}
}
public static void all(){
for (String string : st) {
System.out.println(string);
}
}
}
package StudentGuanLi;
public class Student {
public String Stuname ;
public String gender ;
public int age;
public int StuNum;
public Student(String stuname, String gender, int age, int stuNum ) {
this.Stuname=Stuname;
this.gender = gender;
this.age = age;
this.StuNum=StuNum;
}
}
我写的很菜;可以指点批评。