黑马微项目

 目录

1 飞机票

2 生成一个五位数验证码

3 数字加密

4 数字解密

5 抢红包

6 双色球系统

7 用户登录

8 金额转换

9 手机号屏蔽

10 罗马数字转换

11 调整字符串

12 初级学生管理系统(学生数据的管理)

13 学生管理系统(用户的相关操作)

14 学生管理系统合体

学生信息类

用户类


1 飞机票

代码实现:

import java.util.Scanner;
public class F1 {public static void main(String[] args) {Scanner input = new Scanner(System.in);System.out.print("请输入票价:  ");double jia = input.nextDouble();System.out.print("请输入月份:  ");int yue = input.nextInt();System.out.print("请输入你所坐飞机舱(经济舱或头等舱)  ");String can = input.next();methodjia(jia,yue,can);}private static void methodjia(double jia, int yue, String can) {if (yue>=5 && yue<=10){if (can.equals("经济舱")){jia=jia*0.85;}else if(can.equals("头等舱")) {jia = jia * 0.9;}elseSystem.out.println("输入错误");return;} else if((yue>10 && yue<=12) || (yue<5 && yue>0)){if (can.equals("头等舱")){jia=jia*0.7;}else if(can.equals("经济舱")){jia=jia*0.65;}elseSystem.out.println("输入错误");return;} else if(yue<0||yue>12){System.out.println("错误");return;}System.out.println(jia);}
}

2 生成一个五位数验证码

代码实现:

import java.util.Random;public class Yzm {public static void main(String[] args) {char []arr = new char[52];Random rand = new Random();for (int i = 0; i < 26; i++) {arr[i] = (char) (65+i);}for (int i = 0; i <26; i++) {arr[i+26] = (char) (97+i);}String s ="";for (int i = 0; i < 4; i++) {char k = arr[rand.nextInt(52)];s=s+k;}int i = rand.nextInt(10);s=s+i;System.out.println(s);}
}

3 数字加密

代码实现:

import java.util.Scanner;public class Jm {public static void main(String[] args) {int num = new Scanner(System.in).nextInt();//输入一个数组jiami(intToArray3(num));//方法调用}private static void jiami(int[] arr) {//加密方法每个位数+5,每个位数对10取模,再倒序for (int i = 0; i < arr.length; i++) {arr[i]+=5;}for (int i = 0; i < arr.length; i++) {arr[i]%=10;}for (int i = 0,j = arr.length-1; i < j; i++,j--) {int temp = arr[i];arr[i] = arr[j];arr[j] = temp;}int num = 0;for (int i = 0; i < arr.length; i++) {num= num*10+arr[i];}System.out.println(num);}private static int[] intToArray3(int num){int len = String.valueOf(num).length();//得到这个数的长度以便创建数组int[] resultArray = new int[len];//创建数组while (num != 0){//给数组一一赋值resultArray[len-1] = num % 10;num = num / 10;len--;}return resultArray;//返回位数组成的数组}
}

4 数字解密

import java.util.*;public class Jiemi {public static void main(String[] args) {int num = new Scanner(System.in).nextInt();jie(int01(num));}private static void jie(int[] arr){for (int i = 0,j=arr.length-1; i < j; i++,j--) {int temp = arr[i];arr[i] = arr[j];arr[j] = temp;}for (int i = 0; i < arr.length; i++) {if (arr[i]+10<15){arr[i] = arr[i]+10;}}
//        4  3  2  1  0  9 8 7 6 5
//        14 13 12 11 10 9 8 7 6 5
//        9  8   7  6 5  4 3 2 1 0for (int i = 0; i < arr.length; i++) {arr[i]-=5;}int shuchu = 0;for (int i = 0; i < arr.length; i++) {shuchu= shuchu*10+arr[i];}System.out.println(shuchu);}private static int[] int01(int num){int len = String.valueOf(num).length();int[] arr = new int[len];while  (num!=0){arr[len-1] = num%10;num/=10;len--;}return arr;}
}

5 抢红包

User类创建

public class User {private String name;private int money;public User(){}public User(String name,int money){this.name=name;this.money=money;}public void show(){System.out.println("Name:"+name+" Money:"+money);}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getMoney() {return money;}public void setMoney(int money) {this.money = money;}
}​

Manage类

import java.util.ArrayList;public class Manager extends User{public Manager(String name, int money) {super(name, money);}public Manager() {super();}
//需要一个集合用来存储发红包的个数以及各个金额public ArrayList<Integer> List(int totalmoney,int count){//发的钱ArrayList<Integer> list = new ArrayList<>();int leftmoney = super.getMoney();//群主总共的钱if(leftmoney < totalmoney) return list;//群主没那么多钱int averagemoney = totalmoney/count;//平均每个人int modemoney = totalmoney%count;//除不尽的余数加在list最后一个for(int i = 0 ; i < count-1 ; i++){list.add(averagemoney);}super.setMoney(leftmoney - totalmoney);//群主剩的钱list.add(modemoney+averagemoney);return list;//返回红包集合}
}

Member类

import java.util.ArrayList;
import java.util.Random;public class Member extends User{public Member() {super();}public Member(String name, int money) {super(name, money);}public void receive(ArrayList<Integer> list){int random = new Random().nextInt(list.size());//随即索引int num = list.remove(random);//将这个数去除,并且取出int money = super.getMoney()+num;//把钱加上super.setMoney(money);//更新前的金额}
}

调用

import java.util.ArrayList;
import java.util.Scanner;public class Using {public static void main(String[] args) {Member A= new Member("贤哥",0);Member B = new Member("超哥",0);Member C = new Member("小哥",0);Manager qun = new Manager("群主",10000);System.out.println("原来的钱");qun.show();A.show();B.show();C.show();System.out.println("================");System.out.println("你想发多少");int F = new Scanner(System.in).nextInt();ArrayList<Integer> list = qun.List(F,3);A.receive(list);B.receive(list);C.receive(list);qun.show();A.show();B.show();C.show();}
}

运行结果:

6 双色球系统

代码实现:

package itheima;import java.util.Scanner;
import java.util.Random;public class seven {public static void main(String[] args) {int [] arr = creatarr();int [] arr1 = maicaipiao();jiage(find(arr,arr1),zuihouyige(arr,arr1));}private static void jiage(int num,int lannum){int hongnum = num-lannum;if (hongnum>=0 && lannum==1 &&hongnum<3){System.out.println("恭喜中奖5元");}else if ((hongnum==4&&lannum==0)||(hongnum==3 && lannum==1)){System.out.println("恭喜中奖10元");}else if ((hongnum==4&&lannum==1)||(hongnum==5 && lannum==0)){System.out.println("恭喜中奖200元");} else if(hongnum==5 && lannum==1){System.out.println("恭喜中奖3000元");}else if(hongnum==6 && lannum==0){System.out.println("恭喜中奖500 0000元");} else if (hongnum==6 && lannum==1) {System.out.println("恭喜中奖1000 0000元");}elseSystem.out.println("一分钱没中");}private static int zuihouyige(int [] arr1,int [] arr2){int lannum=0;if (arr1[6]==arr2[6]){lannum=1;}return lannum;}private static int[] maicaipiao(){Scanner P = new Scanner(System.in);//int[] arr = new int[]{P.nextInt(),P.nextInt(),P.nextInt(),P.nextInt(),P.nextInt(),P.nextInt(),P.nextInt()};int[] arr = new int[7];for (int i = 0; i < 6;) {System.out.println("输入第"+(i+1)+"个数:");int num = P.nextInt();if (num >0 && num<34) {if (isPrime(arr,num)){arr[i] = num;i++;}elseSystem.out.println("已经存在");}elseSystem.out.println("输入范围错误");}System.out.println("输入第7个数:");while(true){int num7= P.nextInt();if (num7>0 && num7<17) {arr[6] = num7;for (int i : arr) {System.out.print(i+" ");}System.out.println(" ");return arr;}elseSystem.out.println("范围错误");}}private static int[] creatarr() {int[] arr = new int[7];//七色球Random rand = new Random();for (int i = 0; i < arr.length-1;) {int suinum = rand.nextInt(33)+1;//前六个数1-33if (isPrime(arr, suinum)) {arr[i] = suinum;i++;}}arr[arr.length-1] = rand.nextInt(16)+1;//第七个数1-16return arr;}private static boolean isPrime(int []arr,int n) {//是不是已经出现没有返回truefor (int i : arr) {if (n==i){return false;}}return true;}private static int find(int[] arr1, int[] arr2) {//多少个相同的int i = 0, j = 0;int count = 0;while (i < arr1.length && j < arr2.length) {if (arr1[i] == arr2[j]) {count++;i++;  // 移动 arr1 的指针j++;  // 移动 arr2 的指针} else if (arr1[i] < arr2[j]) {i++;} else {j++;}}return count;}
}

7 用户登录

代码实现

用户名三次机会出错退出系统。

用户名正确进入系统输入密码,密码三次错误锁定用户。

import java.util.Scanner;public class User {public static void main(String[] args) {String Username = "anxian";String UserPassword = "123456";Scanner sc = new Scanner(System.in);String username = null;int num = 0;while (num < 3) {System.out.println("输入你的用户名:");username = sc.nextLine();if (username.equals(Username)) {break;}else {num++;System.out.println("用户名错误,你还有"+(3-num)+"次机会");}}if (username.equals(Username)) {for (int i = 0; i < 3; i++) {System.out.println("输入你的密码:");String password = sc.nextLine();if (password.equals(UserPassword)) {System.out.println("登陆成功");break;} else {System.out.println("信息错误还有" + (2 - i) + "次机会");if (2-i == 0){System.out.println("用户"+Username+"被锁定,请联系客服。");}}}}}
}

8 金额转换

import java.util.Scanner;public class abc {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int n;while (true){System.out.println("enter a number");n = sc.nextInt();if ( n>0 && n<9999999 ){break;}elseSystem.out.println("输入错误");}String str="";do {int g = n % 10;n = n / 10;str = daxie(g).concat(str);//变成大写} while (n != 0);int len = str.length();for (int i = 0; i < (7-len); i++) {//把前置零加上String s = "零";str = s.concat(str);}
//方法一
//        char []arr = str.toCharArray();//变成字符数组
//        String last = "";
//        last +=arr[0]+"百";
//        last+=arr[1]+"拾";
//        last+=arr[2]+"万";
//        last+=arr[3]+"千";
//        last+=arr[4]+"百";
//        last+=arr[5]+"拾";
//        last+=arr[6]+"元";
//        System.out.println(last);//方法二String []arrs = {"百","拾","万","千","百","拾","元"};for (int i = 0; i < str.length(); i++) {char ch = str.charAt(i);System.out.print(ch);System.out.print(arrs[i]);}}private static String daxie(int n){String []arr = {"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};return arr[n];}
}

9 手机号屏蔽

import java.util.Scanner;public class abc {public static void main(String[] args) {Scanner sc = new Scanner(System.in);String str = sc.nextLine();String str1 = str.substring(0, 3);String str2 = str.substring(str.length()-4);System.out.println(str1+"****"+str2);}
}

10 罗马数字转换

 代码实现

import java.util.Scanner;public class abc {public static void main(String[] args) {System.out.println("输入一个数字");Scanner sc = new Scanner(System.in);String str;while (true) {str = sc.next();boolean flag = Isintnum(str);if (flag) {break;}elseSystem.out.println("请重新输入");}StringBuilder p = new StringBuilder();for (char c : str.toCharArray()) {int i = c - '0';p.append(Luoma(i));}System.out.println(p);}private static String Luoma(int num){String [] arr =  {"","I ","II ","III ","IV ","V ","VI ","VII ","VIII ","IX "};return arr[num];}private static boolean Isintnum(String str){for (int i = 0; i < str.length(); i++) {if (str.charAt(i) < '0' || str.charAt(i) > '9') {return false;}}return true;}
}

11 调整字符串

代码实现

import java.util.Scanner;public class abc {public static void main(String[] args) {Scanner sc = new Scanner(System.in);String next = sc.next();String next2 = sc.next();boolean flag = false;for (int i = 0; i < next.length(); i++) {next = xuanzhuan(next);if (next2.equals(next)) {System.out.println("YES");flag = true;}}if (!flag) {System.out.println("NO");}}private static String xuanzhuan(String next){String s;s = next.charAt(0)+"";next = next.substring(1);next = next+s;return next;}
}

12 初级学生管理系统(学生数据的管理)

创建一个学生类

public class Student {private String id;private String name;private int age;private String address;public Student() {}public Student(String id, String name, int age,String address) {this.id = id;this.name = name;this.age = age;}public String getId() {return id;}public void setId(String 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 getAddress() {return address;}public void setAddress(String address) {this.address = address;}
}

相关方法的实现

import java.util.ArrayList;
import java.util.Scanner;public class StudentManage {public static void main(String[] args) {ArrayList<Student> students = new ArrayList<>();loop: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(" ");System.out.print("输入你的需求: ");Scanner sc = new Scanner(System.in);int choice = sc.nextInt();switch (choice) {case 1: addstudent(students);break;case 2: delstudent(students);break;case 3: changestudent(students);break;case 4: squrestudent(students);break;case 5: {System.out.println("已退出学生管理系统");break loop;} default:System.out.println("没有这个选项,请重新输入:");}}}private static void squrestudent(ArrayList<Student> students) {//查询遍历,(空学生表的判断)if (students.isEmpty()) {System.out.println("请添加后再查询");}else{System.out.println("id       姓名 年龄 住址");for (Student student : students) {System.out.println(student.getId() + " " + student.getName()+ " " + student.getAge() + " " + student.getAddress());}}}private static void changestudent(ArrayList<Student> students) {//更改学生表的成员,根据id信息更改if (students.isEmpty()) {System.out.println("请添加后再更改");}else{Scanner sc = new Scanner(System.in);System.out.println("输入id");String id = sc.next();if(!idtest(students, id)){System.out.println("id 匹配成功");System.out.println("输入姓名");String name = sc.next();System.out.println("输入年龄");int age = sc.nextInt();System.out.println("输入地址");String address = sc.next();for (Student student : students) {if (student.getId().equals(id)) {student.setId(id);student.setName(name);student.setAge(age);student.setAddress(address);System.out.println("更改成功");}}}elseSystem.out.println("无这个 id 信息,请重新选择你的需求");}}private static void delstudent(ArrayList<Student> students) {//删除学生表成员信息,要判断是否存在System.out.println("请输入id信息");Scanner sc = new Scanner(System.in);String id = sc.next();for (int i = 0; i < students.size(); i++) {if (students.get(i).getId().equals(id)) {students.remove(i);System.out.println("删除成功");break;}if ( i == students.size() - 1) {System.out.println("无这个学生信息,请添加之后再进行操作");}}}private static void addstudent(ArrayList<Student> students) {//添加学生表成员信息//        System.out.println("分别输入  id  姓名  年龄  住址");
//        Scanner sc = new Scanner(System.in);
//        Student student = new Student(sc.next(),sc.next(),sc.nextInt(),sc.next());//添加方法一
//        students.add(student);Student student = new Student();Scanner sc = new Scanner(System.in);//添加方法二System.out.println("输入id");while(true){String id = sc.next();if (idtest(students,id)) {student.setId(id);break;}elseSystem.out.println("id已经存在 请重新输入");}System.out.println("输入姓名");String name = sc.next();student.setName(name);System.out.println("输入年龄");int age = sc.nextInt();student.setAge(age);System.out.println("输入住址");String address = sc.next();student.setAddress(address);students.add(student);System.out.println("学生信息添加成功");}private static boolean idtest(ArrayList<Student> students,String id) { // 不存在返回truefor (Student student : students) {if (student.getId().equals(id)) {return false;}}return true;}
}

13 学生管理系统(用户的相关操作)

三种需求

用户账号注册

用户账号登陆

用户忘记密码

代码实现

1 用户类

public class UserPro {private String USerName;private String Password;private String phoneNum;private String personId;public UserPro() {}public UserPro(String USerName, String Password, String phoneNum, String personId) {this.USerName = USerName;this.Password = Password;this.phoneNum = phoneNum;this.personId = personId;}public String getUSerName() {return USerName;}public void setUSerName(String USerName) {this.USerName = USerName;}public String getPassword() {return Password;}public void setPassword(String password) {Password = password;}public String getPhoneNum() {return phoneNum;}public void setPhoneNum(String phoneNum) {this.phoneNum = phoneNum;}public String getPersonId() {return personId;}public void setPersonId(String personId) {this.personId = personId;}
}

2 登录的具体模块实现

import java.util.*;public class StuProMax {public static void main(String[] args) {ArrayList<UserPro> userPros = new ArrayList<>();Scanner sc = new Scanner(System.in);while (true) {System.out.println("欢迎来到学生管理系统");System.out.println("请输入你的需求: 1 ->登录 2-> 注册 3-> 找回密码 4-> 退出系统");int a = sc.nextInt();switch (a) {case 1:dengLu(userPros);break;case 2:zhuCe(userPros);break;case 3:zhaoHui(userPros);break;case 4:System.out.println("感谢使用");System.exit(0);default:System.out.println("没有这个选项");}}}private static void zhuCe(ArrayList<UserPro> userPros) {//新建对象UserPro P = new UserPro();//首先用户名输入Scanner sc = new Scanner(System.in);//用于判断用户名是否添加成功boolean yongHu = false;//给定三次机会创建for (int i = 0; i < 3; i++) {System.out.println("请输入你要创建的用户名");String name = sc.next();//用户名的规范性问题//用于统计大小写数字个数int count = 0, count1 = 0, count2 = 0;//判断是否存在用户名(唯一性)boolean equals = false;for (UserPro userPro : userPros) {equals = userPro.getUSerName().equals(name);}if (!equals) {//长度问题if (name.length() >= 3 && name.length() <= 15) {for (char c : name.toCharArray()) {//需要为大小写加数字if (c >= 'A' && c <= 'Z') {count += 1;} else if (c >= 'a' && c <= 'z') {count1 += 1;} else if (c >= '0' && c <= '9') {count2 += 1;} else {System.out.println("非法符号,你还有"+(2-i)+"次机会");break;}}} elseSystem.out.println("用户名长度错误,你还有"+(2-i)+"次机会");}if (count > 0 && count1 > 0 && count2 > 0) {P.setUSerName(name);System.out.println("用户名注册成功");yongHu = true;break;} elseSystem.out.println("需要存在大写字母小写字母数字,你还有"+(2-i)+"次机会");}//密码输入//判断密码输入是否完成boolean passWordFirsts = false;loop:if (yongHu) {while (true) {//两次密码需要相同System.out.println("请输入密码:");String passWordFirst = sc.next();System.out.println("再次确认密码:");String passWordSecond = sc.next();if (passWordFirst.equals(passWordSecond) && passWordFirst.length() >= 6) {P.setPassword(passWordFirst);System.out.println("密码设置成功");passWordFirsts = true;break loop;} elseSystem.out.println("两次设置的密码不相同或者密码位数未达到六位,请重新输入");}}//身份证号的输入boolean personIds = false;loop:if (passWordFirsts){while (true){System.out.println("请输入你的身份证号");String personId = sc.next();if (personId.length()==18) {if (personId.charAt(0) != '0'){String personId2 = personId.substring(0,personId.length()-1);int countNum = 0;if ((personId.charAt(17) >= '0'&& personId.charAt(17) <= '9') || personId.charAt(17) =='x'|| personId.charAt(17) =='X'){for (char c : personId2.toCharArray()) {if (c >= '0' && c <= '9') {countNum += 1;if (countNum == 17){P.setPersonId(personId);System.out.println("身份证验证成功");personIds = true;break loop;}}}}elseSystem.out.println("最后一位数必须是数字或者x,X");}elseSystem.out.println("首位数需要不为0");}elseSystem.out.println("长度错误");}}//手机号的输入boolean phoneNums = false;loop:if (personIds){while (true){System.out.println("请输入你的手机号:");String phoneNum = sc.next();int countNums = 0;if (phoneNum.length() == 11 && phoneNum.charAt(0) == '1') {for (char c : phoneNum.toCharArray()) {if (c >= '0' && c <= '9') {countNums += 1;if (countNums == 11){P.setPhoneNum(phoneNum);System.out.println("电话号码验证成功");phoneNums = true;break loop;}}}}elseSystem.out.println("手机号位数输入错误,或者首位数字不为1");}}if (phoneNums){userPros.add(P);System.out.println("恭喜你注册成功");}else{System.out.println("注册失败");System.out.println();}}private static void zhaoHui (ArrayList<UserPro> userPros) {Scanner input = new Scanner(System.in);System.out.println("输入你的账户名");//判断账户名是否存在boolean yongHu = false;String yongHuName = input.next();for (UserPro i : userPros) {if (i.getUSerName().equals(yongHuName)) {yongHu = true;System.out.println("请输入你的手机号码");String phoneNum = input.next();if (phoneNum.equals(i.getPhoneNum())) {System.out.println("请输入你的身份证号码");String personID = input.next();if (personID.equals(i.getPersonId())) {while (true) {//两次密码需要相同System.out.println("请输入新密码:");String passWordFirst = input.next();System.out.println("再次确认密码:");String passWordSecond = input.next();if (passWordFirst.equals(passWordSecond) && passWordFirst.length() >= 6) {i.setPassword(passWordFirst);System.out.println("密码设置成功");break;} elseSystem.out.println("两次设置的密码不相同,或者密码位数未达到6位,请重新输入");}}elseSystem.out.println("身份证号码验证失败");}elseSystem.out.println("手机号码验证失败");}if (!yongHu) {System.out.println("账户未存在");}}}private static void dengLu(ArrayList<UserPro> userPros) {Scanner input = new Scanner(System.in);System.out.println("输入你的账户名");//判断账户名是否输入成功boolean yongHu = false;String userDeng = input.next();for (UserPro i: userPros){if (i.getUSerName().equals(userDeng)) {yongHu = true;System.out.println("账号输入正确");for (int j = 0; j < 3;) {System.out.println("请输入你的密码:");String userMiMa = input.next();if (userMiMa.equals(i.getPassword())) {j+=3;System.out.println("密码正确");for (int k = 0; k < 3;) {System.out.println("这是一段验证码");String yanZeng = yanZengMa();System.out.println(yanZeng);System.out.println("请输入验证码确认");String next = input.next();if (next.equals(yanZeng)) {System.out.println("验证码输入正确,登陆成功");k+=3;}else{k++;System.out.println("验证码输入错误你还有"+(3-k)+"次机会");}}} else {j++;System.out.println("密码错误你还有"+(3-j)+"次机会");}}}}if (!yongHu){System.out.println("用户尚未注册或者你的密码多次错误或者验证码多次出错,请重试");}}private static String yanZengMa(){//验证码生成程序char []arr = new char[52];Random rand = new Random();for (int i = 0; i < 26; i++) {arr[i] = (char) (65+i);}for (int i = 0; i <26; i++) {arr[i+26] = (char) (97+i);}StringBuilder s = new StringBuilder();for (int i = 0; i < 4; i++) {char k = arr[rand.nextInt(52)];s.append(k);}//4个大小写1个数字int i = rand.nextInt(10);s.append(i);return s.toString();}}

14 学生管理系统合体

学生信息类

public class Student {private String id;private String name;private int age;private String address;public Student() {}public Student(String id, String name, int age,String address) {this.id = id;this.name = name;this.age = age;}public String getId() {return id;}public void setId(String 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 getAddress() {return address;}public void setAddress(String address) {this.address = address;}
}

用户类

public class UserPro {private String USerName;private String Password;private String phoneNum;private String personId;public UserPro() {}public UserPro(String USerName, String Password, String phoneNum, String personId) {this.USerName = USerName;this.Password = Password;this.phoneNum = phoneNum;this.personId = personId;}public String getUSerName() {return USerName;}public void setUSerName(String USerName) {this.USerName = USerName;}public String getPassword() {return Password;}public void setPassword(String password) {Password = password;}public String getPhoneNum() {return phoneNum;}public void setPhoneNum(String phoneNum) {this.phoneNum = phoneNum;}public String getPersonId() {return personId;}public void setPersonId(String personId) {this.personId = personId;}
}

管理系统

import java.util.*;public class StuProMax {public static void main(String[] args) {ArrayList<UserPro> userPros = new ArrayList<>();Scanner sc = new Scanner(System.in);while (true) {System.out.println("欢迎来到学生管理系统");System.out.println("请输入你的需求: 1 ->登录 2-> 注册 3-> 找回密码 4-> 退出系统");int a = sc.nextInt();switch (a) {case 1:dengLu(userPros);break;case 2:zhuCe(userPros);break;case 3:zhaoHui(userPros);break;case 4:System.out.println("感谢使用");System.exit(0);default:System.out.println("没有这个选项");}}}private static void zhuCe(ArrayList<UserPro> userPros) {//新建对象UserPro P = new UserPro();//首先用户名输入Scanner sc = new Scanner(System.in);//用于判断用户名是否添加成功boolean yongHu = false;//给定三次机会创建for (int i = 0; i < 3; i++) {System.out.println("请输入你要创建的用户名");String name = sc.next();//用户名的规范性问题//用于统计大小写数字个数int count = 0, count1 = 0, count2 = 0;//判断是否存在用户名(唯一性)boolean equals = false;for (UserPro userPro : userPros) {equals = userPro.getUSerName().equals(name);}if (!equals) {//长度问题if (name.length() >= 3 && name.length() <= 15) {for (char c : name.toCharArray()) {//需要为大小写加数字if (c >= 'A' && c <= 'Z') {count += 1;} else if (c >= 'a' && c <= 'z') {count1 += 1;} else if (c >= '0' && c <= '9') {count2 += 1;} else {System.out.println("非法符号,你还有"+(2-i)+"次机会");break;}}} elseSystem.out.println("用户名长度错误,你还有"+(2-i)+"次机会");}if (count > 0 && count1 > 0 && count2 > 0) {P.setUSerName(name);System.out.println("用户名注册成功");yongHu = true;break;} elseSystem.out.println("需要存在大写字母小写字母数字,你还有"+(2-i)+"次机会");}//密码输入//判断密码输入是否完成boolean passWordFirsts = false;loop:if (yongHu) {while (true) {//两次密码需要相同System.out.println("请输入密码:");String passWordFirst = sc.next();System.out.println("再次确认密码:");String passWordSecond = sc.next();if (passWordFirst.equals(passWordSecond) && passWordFirst.length() >= 6) {P.setPassword(passWordFirst);System.out.println("密码设置成功");passWordFirsts = true;break loop;} elseSystem.out.println("两次设置的密码不相同或者密码位数未达到六位,请重新输入");}}//身份证号的输入boolean personIds = false;loop:if (passWordFirsts){while (true){System.out.println("请输入你的身份证号");String personId = sc.next();if (personId.length()==18) {if (personId.charAt(0) != '0'){String personId2 = personId.substring(0,personId.length()-1);int countNum = 0;if ((personId.charAt(17) >= '0'&& personId.charAt(17) <= '9') || personId.charAt(17) =='x'|| personId.charAt(17) =='X'){for (char c : personId2.toCharArray()) {if (c >= '0' && c <= '9') {countNum += 1;if (countNum == 17){P.setPersonId(personId);System.out.println("身份证验证成功");personIds = true;break loop;}}}}elseSystem.out.println("最后一位数必须是数字或者x,X");}elseSystem.out.println("首位数需要不为0");}elseSystem.out.println("长度错误");}}//手机号的输入boolean phoneNums = false;loop:if (personIds){while (true){System.out.println("请输入你的手机号:");String phoneNum = sc.next();int countNums = 0;if (phoneNum.length() == 11 && phoneNum.charAt(0) == '1') {for (char c : phoneNum.toCharArray()) {if (c >= '0' && c <= '9') {countNums += 1;if (countNums == 11){P.setPhoneNum(phoneNum);System.out.println("电话号码验证成功");phoneNums = true;break loop;}}}}elseSystem.out.println("手机号位数输入错误,或者首位数字不为1");}}if (phoneNums){userPros.add(P);System.out.println("恭喜你注册成功");}else{System.out.println("注册失败");System.out.println();}}private static void zhaoHui (ArrayList<UserPro> userPros) {Scanner input = new Scanner(System.in);System.out.println("输入你的账户名");//判断账户名是否存在boolean yongHu = false;String yongHuName = input.next();for (UserPro i : userPros) {if (i.getUSerName().equals(yongHuName)) {yongHu = true;System.out.println("请输入你的手机号码");String phoneNum = input.next();if (phoneNum.equals(i.getPhoneNum())) {System.out.println("请输入你的身份证号码");String personID = input.next();if (personID.equals(i.getPersonId())) {while (true) {//两次密码需要相同System.out.println("请输入新密码:");String passWordFirst = input.next();System.out.println("再次确认密码:");String passWordSecond = input.next();if (passWordFirst.equals(passWordSecond) && passWordFirst.length() >= 6) {i.setPassword(passWordFirst);System.out.println("密码设置成功");break;} elseSystem.out.println("两次设置的密码不相同,或者密码位数未达到6位,请重新输入");}}elseSystem.out.println("身份证号码验证失败");}elseSystem.out.println("手机号码验证失败");}if (!yongHu) {System.out.println("账户未存在");}}}private static void dengLu(ArrayList<UserPro> userPros) {Scanner input = new Scanner(System.in);System.out.println("输入你的账户名");//判断账户名是否输入成功boolean yongHu = false;String userDeng = input.next();for (UserPro i: userPros){if (i.getUSerName().equals(userDeng)) {yongHu = true;System.out.println("账号输入正确");for (int j = 0; j < 3;) {System.out.println("请输入你的密码:");String userMiMa = input.next();if (userMiMa.equals(i.getPassword())) {j+=3;System.out.println("密码正确");for (int k = 0; k < 3;) {System.out.println("这是一段验证码");String yanZeng = yanZengMa();System.out.println(yanZeng);System.out.println("请输入验证码确认");String next = input.next();if (next.equals(yanZeng)) {System.out.println("验证码输入正确,登陆成功");k+=3;ArrayList<Student> students = new ArrayList<>();loop: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(" ");System.out.print("输入你的需求: ");Scanner sc = new Scanner(System.in);int choice = sc.nextInt();switch (choice) {case 1: addstudent(students);break;case 2: delstudent(students);break;case 3: changestudent(students);break;case 4: squrestudent(students);break;case 5: {System.out.println("已退出学生管理系统");break loop;} default:System.out.println("没有这个选项,请重新输入:");}}}else{k++;System.out.println("验证码输入错误你还有"+(3-k)+"次机会");}}} else {j++;System.out.println("密码错误你还有"+(3-j)+"次机会");}}}}if (!yongHu){System.out.println("用户尚未注册或者你的密码多次错误或者验证码多次出错,请重试");}}private static String yanZengMa(){//验证码生成程序char []arr = new char[52];Random rand = new Random();for (int i = 0; i < 26; i++) {arr[i] = (char) (65+i);}for (int i = 0; i <26; i++) {arr[i+26] = (char) (97+i);}StringBuilder s = new StringBuilder();for (int i = 0; i < 4; i++) {char k = arr[rand.nextInt(52)];s.append(k);}//4个大小写1个数字int i = rand.nextInt(10);s.append(i);return s.toString();}private static void squrestudent(ArrayList<Student> students) {//查询遍历,(空学生表的判断)if (students.isEmpty()) {System.out.println("请添加后再查询");}else{System.out.println("id       姓名 年龄 住址");for (Student student : students) {System.out.println(student.getId() + " " + student.getName()+ " " + student.getAge() + " " + student.getAddress());}}}private static void changestudent(ArrayList<Student> students) {//更改学生表的成员,根据id信息更改if (students.isEmpty()) {System.out.println("请添加后再更改");}else{Scanner sc = new Scanner(System.in);System.out.println("输入id");String id = sc.next();if(!idtest(students, id)){System.out.println("id 匹配成功");System.out.println("输入姓名");String name = sc.next();System.out.println("输入年龄");int age = sc.nextInt();System.out.println("输入地址");String address = sc.next();for (Student student : students) {if (student.getId().equals(id)) {student.setId(id);student.setName(name);student.setAge(age);student.setAddress(address);System.out.println("更改成功");}}}elseSystem.out.println("无这个 id 信息,请重新选择你的需求");}}private static void delstudent(ArrayList<Student> students) {//删除学生表成员信息,要判断是否存在System.out.println("请输入id信息");Scanner sc = new Scanner(System.in);String id = sc.next();for (int i = 0; i < students.size(); i++) {if (students.get(i).getId().equals(id)) {students.remove(i);System.out.println("删除成功");break;}if ( i == students.size() - 1) {System.out.println("无这个学生信息,请添加之后再进行操作");}}}private static void addstudent(ArrayList<Student> students) {//添加学生表成员信息//        System.out.println("分别输入  id  姓名  年龄  住址");
//        Scanner sc = new Scanner(System.in);
//        Student student = new Student(sc.next(),sc.next(),sc.nextInt(),sc.next());//添加方法一
//        students.add(student);Student student = new Student();Scanner sc = new Scanner(System.in);//添加方法二System.out.println("输入id");while(true){String id = sc.next();if (idtest(students,id)) {student.setId(id);break;}elseSystem.out.println("id已经存在 请重新输入");}System.out.println("输入姓名");String name = sc.next();student.setName(name);System.out.println("输入年龄");int age = sc.nextInt();student.setAge(age);System.out.println("输入住址");String address = sc.next();student.setAddress(address);students.add(student);System.out.println("学生信息添加成功");}private static boolean idtest(ArrayList<Student> students,String id) { // 不存在返回truefor (Student student : students) {if (student.getId().equals(id)) {return false;}}return true;}}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.xdnf.cn/news/16565.html

如若内容造成侵权/违法违规/事实不符,请联系一条长河网进行投诉反馈,一经查实,立即删除!

相关文章

基于lighthouse搭建私有网盘Cloudreve【开源应用实践】

基于lighthouse搭建私有网盘Cloudreve【超高性价比】 今天给大家分享一款私人网盘神器&#xff0c;既能存放你的文件文档&#xff0c;也能替你保存那不可告人的秘密~ 香菇今天将手把手教给大家如何在腾讯云轻量应用服务器上搭建个人专属网盘 1. 既爱又恨的网盘存储 很多小伙伴…

博物馆实景复刻:开启沉浸式文化体验的新篇章

随着数字化技术的飞速发展&#xff0c;博物馆的展览形式正在经历一场前所未有的变革。3数字博物馆和3D线上展览&#xff0c;这种创新的展览方式不仅打破了时间和空间的限制&#xff0c;更让文化遗产的保护与传承迈上了一个新的台阶。 本文将深入探讨博物馆实景复刻虚拟展厅的兴…

java中设计模式的使用(持续更新中)

概述 设计模式的目的&#xff1a;编写软件过程中&#xff0c;程序员面临着来自耦合性&#xff0c;内聚性以及可维护性&#xff0c;可扩展性&#xff0c;重用性&#xff0c;灵活性等多方面的挑战&#xff0c;设计模式是为了让程序&#xff08;软件&#xff09;&#xff0c;具有…

linux基础io重定向

文章目录 目录 文章目录 前言 一、函数的认识 1、认识close函数和dup2函数 1、close函数&#xff1a; ​编辑 2、write、read函数 1、write函数 2、read函数 二、重定向 1.引入函数dup2 ​编辑 2、输出重定向 3.输出重定向 三、myshell重定向 总结 前言 接上一篇&#xff0c;…

[STM32] 定时器应用之输出比较 (五)

文章目录 1.输出比较2.PWM 介绍3.配置PWM 1.输出比较 OC: 输出比较。 输出比较可以通过比较CNT与CCR寄存器值的关系&#xff0c;来对输出电平进行置1、置0或翻转的操作&#xff0c;用于输出一定频率和占空比的PWM波形。每个高级定时器和通用定时器都拥有4个输出比较通道高级定…

【计算机毕设】无查重 基于python豆瓣电影评论舆情数据可视化系统(完整系统源码+数据库+开发笔记+详细部署教程)✅

目录 【计算机毕设】无查重 基于python豆瓣电影数据可视化系统&#xff08;完整系统源码数据库开发笔记详细部署教程&#xff09;✅ 一、项目背景 二、项目目标 三、项目功能 四、开发技术介绍 五、数据库设计 六、项目展示 七、开发笔记 八、启动步骤文档 九、权威教…

后台管理系统窗体程序:个人中心

目录 个人中心的功能介绍&#xff1a; 1、进入页面 2、页面内的各种功能设计 &#xff08;1&#xff09;修改按钮 &#xff08;2&#xff09;页面的进入退出操作 一、网页设计 二、html代码 三、css代码 四、js代码 本次项目为后台管理系统&#xff0c;在本系统内的第七…

PLC如何支持GEM300标准?SECS/GEM通讯协议

1. 提供技术服务&#xff0c;保证户使用没问题 2. 支持市场所有的常规PLC 3. 支持常规组态软件&#xff0c;如wincc、组态王、组态屏等 4. 支持各类传感器&#xff0c;私有协议、modbus、web等 5. 无需二次开发&#xff0c;只需配置映射到已有的PLC地址 GEM300协议是为了满…

用 Google Sheets 表格增强 Tableau 数据分析的 3 种玩法

轻松实现文本翻译、网页数据抓取&#xff0c;甚至创建高级日期表来增强 Tableau 可视化效果&#xff01; 作为一款强大的数据可视化工具&#xff0c;Tableau 的可视化能力毋庸置疑。然而&#xff0c;对于跟表格打交道的用户来说&#xff0c;它没有“创建表格”的功能&#xff0…

计算机网络 (3)计算机网络的性能

一、计算机网络性能指标 速率&#xff1a; 速率是计算机网络中最重要的性能指标之一&#xff0c;它指的是数据的传送速率&#xff0c;也称为数据率&#xff08;Data Rate&#xff09;或比特率&#xff08;Bit Rate&#xff09;。速率的单位是比特/秒&#xff08;bit/s&#xff…

CAP与BASE分布式理论

CAP理论 C&#xff1a;Consistency 一致性&#xff1a;指强一致性&#xff0c;分布式系统中的所有节点在同一时刻具有同样的值、都是最新的数据副本&#xff0c;一致性保证了不管向哪台服务器写入数据&#xff0c;其他的服务器能实时同步数据 强一致性&#xff1a;写入数据的时…

【Java基础知识系列】之Java类的初始化顺序

前言 类的初始化顺序 简单场景 代码示例 public class Person {private String name initName();private String initName() {System.out.println("【父类】初始化实例变量name");return "【父类】史蒂夫";}private int age;private static int staticVa…

探索大规模语言模型(LLM)在心理健康护理领域中的应用与潜力

概述 心理健康是公共卫生最重要的领域之一。根据美国国家精神卫生研究所&#xff08;NIMH&#xff09;的数据&#xff0c;到 2021 年&#xff0c;22.8% 的美国成年人将患上某种形式的精神疾病。在全球范围内&#xff0c;精神疾病占非致命性疾病负担的 30%&#xff0c;并被世界…

解决 idea windows 设置maven离线模式之后,maven继续请求远程仓库

在内网开发的时候经常遇到没有办法来链接远程仓库的情况&#xff0c;这个时候需要设置maven的离线模式。 idea windows 设置maven离线模式之后&#xff0c;maven继续请求远程仓库 当设置完离线模式之后&#xff0c;有的时候执行maven的命令会报错&#xff0c;提示请求远程失败…

卷积神经网络 (CNN)

代码功能 网络结构&#xff1a; 卷积层&#xff1a; 两个卷积层&#xff0c;每个卷积层后接 ReLU 激活函数。 最大池化层用于降低维度。 全连接层&#xff1a; 使用一个隐藏层&#xff08;128 个神经元&#xff09;和一个输出层&#xff08;10 类分类任务&#xff09;。 数据集…

等保二级需要哪些安全设备?

在信息化高速发展的今天&#xff0c;服务器的安全性成为了企业乃至国家信息安全的重要基石。等保二级&#xff0c;作为信息安全等级保护制度中的一个关键环节&#xff0c;对服务器的安全防护提出了明确要求。本文将详细阐述服务器等保二级所需的各种安全设备&#xff0c;旨在为…

C++【深入项目-检测键盘】

神马是检测键盘&#xff0c;就是让编辑器可以检测键盘按下了什么按键&#xff0c;我们先科普复习检测键盘 。 检测键盘需要用到一些函数&#xff0c;请见下&#xff1a; ! KEY_DOWN( 80 ) 这个代码是检测按下键盘上P按键。那80是什么&#xff1f;原来是对应按键的&#xff0…

问题An object named ‘ResNetArcFace‘ was already registered in ‘arch‘ registry!

在安装 GFPGAN 的时候&#xff0c;一切都顺利&#xff0c;但是执行的时候出现了错误&#xff0c;哦还有一个问题&#xff0c; 问题一 就是如果basicsr安装不成功可以执行如下命令 pip install -i https://mirrors.aliyun.com/pypi/simple tb-nightly pip install -i https:/…

Leecode刷题C语言之最少翻转次数使二进制矩阵回文①

执行结果:通过 执行用时和内存消耗如下&#xff1a; 题目&#xff1a;最少翻转次数使二进制矩阵回文① 给你一个 m x n 的二进制矩阵 grid 。如果矩阵中一行或者一列从前往后与从后往前读是一样的&#xff0c;那么我们称这一行或者这一列是 回文 的。你可以将 grid 中任意格子…

K8S containerd拉取harbor镜像

前言 接前面的环境 K8S 1.24以后开始启用docker作为CRI&#xff0c;这里用containerd拉取 正文 vim /etc/containerd/config.toml #修改内容如下 #sandbox_image "registry.aliyuncs.com/google_containers/pause:3.10" systemd_cgroup true [plugins."io.…