首页 > 其他分享 >学生管理系统

学生管理系统

时间:2022-10-10 19:59:33浏览次数:36  
标签:String 管理系统 list System 学生 println id out

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

public class user {
private String id;
private String password;
private String idcard;
private String phone;

public user() {
}

public user(String id, String password, String idcard, String phone) {
this.id = id;
this.password = password;
this.idcard = idcard;
this.phone = phone;
}

public String getId() {
return this.id;
}

public void setId(String id) {
this.id = id;
}

public String getPassword() {
return this.password;
}

public void setPassword(String password) {
this.password = password;
}

public String getIdcard() {
return this.idcard;
}

public void setIdcard(String idcard) {
this.idcard = idcard;
}

public String getPhone() {
return this.phone;
}

public void setPhone(String phone) {
this.phone = phone;
}
}
//这个是一个类
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

import java.util.ArrayList;
import java.util.Random;

public class test {
public test() {
}

public static void main(String[] args) {
Random r = new Random();
ArrayList<Character> list = new ArrayList();

for(int i = 0; i < 26; ++i) {
list.add((char)(97 + i));
list.add((char)(65 + i));
}

StringBuilder sb = new StringBuilder();

int number;
int index;
for(number = 0; number < 4; ++number) {
int index = r.nextInt(26);
index = (Character)list.get(index);
sb.append((char)index);
}

number = r.nextInt(10);
sb.append(number);
char[] arr = sb.toString().toCharArray();
index = r.nextInt(5);
char temp = arr[4];
arr[4] = arr[index];
arr[index] = temp;
System.out.println(arr);
}
}
//这个是第二个
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

import java.util.ArrayList;
import java.util.Scanner;

public class students {
public students() {
}

public static void studentstart() {
ArrayList<student> list = new ArrayList();

while(true) {
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("请输入你的选择:");
Scanner sc = new Scanner(System.in);
int choose = sc.nextInt();
switch (choose) {
case 1:
System.out.println("添加学生");
add(list);
break;
case 2:
System.out.println("删除学生");
delete(list);
break;
case 3:
System.out.println("修改学生");
xiugai(list);
break;
case 4:
System.out.println("查询学生");
chaxun(list);
break;
case 5:
System.exit(0);
}
}
}
}

public static void add(ArrayList<student> list) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入学生的姓名:");
String name = sc.next();
System.out.println("请输入学生的id:");
String id = sc.next();
System.out.println("请输入学生的年龄:");
int age = sc.nextInt();
System.out.println("请输入学生的家庭住址:");
String address = sc.next();
student s = new student(name, age, id, address);
list.add(s);
System.out.println("添加成功");
}

public static void delete(ArrayList<student> list) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入你要删除的id:");
String id = sc.next();
int index = -1;

for(int i = 0; i < list.size(); ++i) {
student s = (student)list.get(i);
if (id.equals(s.getId())) {
index = i;
}
}

if (index == -1) {
System.out.println("id不存在");
} else {
list.remove(index);
System.out.println(id + "已删除");
}
}

public static void chaxun(ArrayList<student> list) {
if (list.size() == 0) {
System.out.println("当前无学生信息,请添加后在查询");
} else {
System.out.println("id\t 姓名\t 年龄 \t 家庭住址\t");

for(int i = 0; i < list.size(); ++i) {
student s = (student)list.get(i);
System.out.println(s.getId() + " " + s.getName() + " " + s.getAge() + " " + s.getAdress());
}

}
}

public static void xiugai(ArrayList<student> list) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入你要修改的id:");
String id = sc.next();
int index = -1;

for(int i = 0; i < list.size(); ++i) {
student s = (student)list.get(i);
if (id.equals(s.getId())) {
index = i;
}
}

if (index == -1) {
System.out.println("该id不存在");
} else {
student s = (student)list.get(index);
System.out.println("请输入要修改学生的姓名");
String aname = sc.next();
s.setName(aname);
System.out.println("请输入要修改学生的id");
String aid = sc.next();
s.setId(aid);
System.out.println("请输入要修改学生的年龄");
int aage = sc.nextInt();
s.setAge(aage);
System.out.println("请输入要修改学生的家庭住址");
String aaddress = sc.next();
s.setAdress(aaddress);
System.out.println("修改成功");
}
}
}
//这个是第三个
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

public class student {
private String name;
private int age;
private String id;
private String adress;

public student() {
}

public student(String name, int age, String id, String adress) {
this.name = name;
this.age = age;
this.id = id;
this.adress = adress;
}

public String getName() {
return this.name;
}

public void setName(String name) {
this.name = name;
}

public int getAge() {
return this.age;
}

public void setAge(int age) {
this.age = age;
}

public String getId() {
return this.id;
}

public void setId(String id) {
this.id = id;
}

public String getAdress() {
return this.adress;
}

public void setAdress(String adress) {
this.adress = adress;
}
}
//这个是第四个
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;

public class denglu {
public denglu() {
}

public static void main(String[] args) {
ArrayList<user> list = new ArrayList();

while(true) {
while(true) {
System.out.println("欢迎来到学生管理系统");
System.out.println("请选择操作 : 1.登录 2.注册 3.忘记密码 4.退出");
Scanner sc = new Scanner(System.in);
int choose = sc.nextInt();
switch (choose) {
case 1:
denglu(list);
break;
case 2:
zhuce(list);
break;
case 3:
forget(list);
break;
case 4:
System.exit(0);
}
}
}
}

public static void denglu(ArrayList<user> list) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入用户名");
String id = sc.next();
boolean flag1 = contains(list, id);
if (flag1) {
System.out.println("用户名不存在,请先注册");
} else {
System.out.println("请输入密码");
String password = sc.next();
String sb = produceY();
System.out.println("请输入验证码");

while(true) {
String yanzhengma = sc.next();
if (yanzhengma.equalsIgnoreCase(sb)) {
user u = new user(id, password, (String)null, (String)null);
boolean flag2 = cheak(list, u);
if (flag2) {
System.out.println("登陆成功");
students ss = new students();
students.studentstart();
} else {
System.out.println("用户名密码错误,登录失败");
}

return;
}

System.out.println("验证码输入错误,请重新输入");
}
}
}

public static void zhuce(ArrayList<user> list) {
Scanner sc = new Scanner(System.in);

while(true) {
while(true) {
System.out.println("请输入注册的用户名:");
String id = sc.next();
boolean flag = idcheak(id);
if (!flag) {
System.out.println("用户名格式错误,请重新输入");
} else {
boolean flag2 = contains(list, id);
if (flag2) {
System.out.println("用户名可用,请输入密码");

while(true) {
String password1 = sc.next();
System.out.println("请确认密码:");
String idcard = sc.next();
if (password1.equals(idcard)) {
System.out.println("两次密码一致,请输入身份证号:");

while(true) {
idcard = sc.next();
boolean flag3 = idcontains(idcard);
if (flag3) {
System.out.println("身份证号符合,请输入手机");

while(true) {
String phone = sc.next();
boolean flag4 = phonecontains(phone);
if (flag4) {
System.out.println("注册成功");
user u1 = new user(id, password1, idcard, phone);
list.add(u1);
return;
}

System.out.println("手机号错误,请重新输入:");
}
}

System.out.println("身份证号不符合,请重新输入");
}
}

System.out.println("两次密码不一致,请重新输入密码");
}
}

System.out.println("用户名重复,请重新输入");
}
}
}
}

public static void forget(ArrayList<user> list) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入用户名");
String id = sc.next();
boolean flag1 = contains(list, id);
if (!flag1) {
System.out.println("用户名未注册,请先注册");
} else {
System.out.println("请输入身份证:");
String idcard = sc.next();
System.out.println("请输入手机号:");
String phone = sc.next();
user u = new user(id, (String)null, idcard, phone);
int index = cheak2(list, u);
if (index != -1) {
user u2 = (user)list.get(index);
System.out.println("信息一致,请输入修改后的密码:");
String password = sc.next();
u2.setPassword(password);
System.out.println("修改成功");
} else {
System.out.println("账号信息不匹配,修改失败");
}

}
}

public static boolean idcheak(String id) {
if (id.length() >= 3 && id.length() <= 15) {
int count;
int i;
for(count = 0; count < id.length(); ++count) {
i = id.charAt(count);
if ((i < 97 || i > 122) && (i < 65 || i > 90) && (i < 48 || i > 57)) {
return false;
}
}

count = 0;

for(i = 0; i < id.length(); ++i) {
char a = id.charAt(i);
if (a >= 'a' && a <= 'z' || a >= 'A' && a <= 'Z') {
++count;
}
}

return count > 0;
} else {
return false;
}
}

public static boolean contains(ArrayList<user> list, String id) {
for(int i = 0; i < list.size(); ++i) {
user u = (user)list.get(i);
if (u.getId().equals(id)) {
return false;
}
}

return true;
}

public static boolean idcontains(String idcard) {
if (idcard.length() != 18) {
return false;
} else {
char a = idcard.charAt(0);
if (a == '0') {
return false;
} else {
for(int i = 0; i < idcard.length() - 1; ++i) {
char b = idcard.charAt(i);
if (b < '0' || b > '9') {
return false;
}
}

char c = idcard.charAt(17);
if ((c > '9' || c < '0') && c != 'x' && c != 'X') {
return false;
} else {
return true;
}
}
}
}

public static boolean phonecontains(String phone) {
if (phone.length() != 11) {
return false;
} else {
char a = phone.charAt(0);
if (a == '0') {
return false;
} else {
for(int i = 0; i < phone.length(); ++i) {
char b = phone.charAt(i);
if (b < '0' || b > '9') {
return false;
}
}

return true;
}
}
}

public static String produceY() {
Random r = new Random();
ArrayList<Character> list = new ArrayList();

for(int i = 0; i < 26; ++i) {
list.add((char)(97 + i));
list.add((char)(65 + i));
}

StringBuilder sb = new StringBuilder();

int number;
int index;
for(number = 0; number < 4; ++number) {
int index = r.nextInt(26);
index = (Character)list.get(index);
sb.append((char)index);
}

number = r.nextInt(10);
sb.append(number);
char[] arr = sb.toString().toCharArray();
index = r.nextInt(5);
char temp = arr[4];
arr[4] = arr[index];
arr[index] = temp;
System.out.println(arr);
return new String(arr);
}

public static boolean cheak(ArrayList<user> list, user u) {
int index = -1;

for(int i = 0; i < list.size(); ++i) {
user u1 = (user)list.get(i);
if (u.getId().equals(u1.getId())) {
index = i;
}
}

user u2 = (user)list.get(index);
if (u.getPassword().equals(u2.getPassword())) {
return true;
} else {
return false;
}
}

public static int cheak2(ArrayList<user> list, user u) {
int index = -1;

for(int i = 0; i < list.size(); ++i) {
user u1 = (user)list.get(i);
if (u.getId().equals(u1.getId())) {
index = i;
}
}

user u2 = (user)list.get(index);
if (u.getIdcard().equals(u2.getIdcard()) && u.getPhone().equals(u2.getPhone())) {
return index;
} else {
return -1;
}
}
}
//这是最后一个

标签:String,管理系统,list,System,学生,println,id,out
From: https://www.cnblogs.com/lin513/p/16776934.html

相关文章