黑马微项目

 目录

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.mzph.cn/pingmian/60663.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C2M柔性制造模式

C2M柔性制造模式&#xff08;Customer-to-Manufacturer&#xff0c;客户到制造商的柔性制造模式&#xff09;是一种新型的生产模式&#xff0c;强调客户需求与制造过程的直接对接&#xff0c;并且能够快速响应和适应客户个性化的定制需求。这种模式结合了定制化生产与智能制造&…

IoT [remote electricity meter]

IoT [remote electricity meter] 物联网&#xff0c;远程抄表&#xff0c;电表数据&#xff0c;举个例子

2、开发工具和环境搭建

万丈高楼平地起&#xff0c;学习C语言先从安装个软件工具开始吧。 1、C语言软件工具有两个作用 1、编辑器 -- 写代码的工具 2、编译器 -- 将代码翻译成机器代码0和1 接下来我们介绍两种C语言代码工具&#xff1a;devcpp 和 VS2019&#xff0c;大家可以根据自己的喜好安装。 dev…

20241115在飞凌的OK3588-C的核心板上跑Linux R4时拿大文件到电脑的方法

20241115在飞凌的OK3588-C的核心板上跑Linux R4时拿大文件到电脑的方法 2024/11/15 15:26 缘起&#xff1a;使用SONY 405的机芯&#xff0c;以1080p60录像了半小时&#xff0c;3.5GB的mp4视频要拿到电脑上播放确认。 方法&#xff1a;1、拷贝到TF卡。记住&#xff0c;对于FAT32…

MySQL一些使用操作-持续更新

MySQL相关操作 1.MySQL不删除数据的情况下&#xff0c;让自增id重新排序 应用场景&#xff1a;Mysql&#xff08;当你删除表中数据之后&#xff0c;造成自增id不连续&#xff0c;可能会导致需要用id进行的判断的时候不准确&#xff0c;所以我想到了要重新排序&#xff0c;当然…

async 和 await的使用

一、需求 点击按钮处理重复提交&#xff0c;想要通过disabled的方式实现。 但是点击按钮调用的方法里有ajax、跳转、弹窗等一系列逻辑操作&#xff0c;需要等方法里流程都走完&#xff0c;再把disabled设为false&#xff0c;这样下次点击按钮时就可以继续走方法里的ajax等操作…

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

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

StructuredStreaming (一)

一、sparkStreaming的不足 1.基于微批,延迟高不能做到真正的实时 2.DStream基于RDD,不直接支持SQL 3.流批处理的API应用层不统一,(流用的DStream-底层是RDD,批用的DF/DS/RDD) 4.不支持EventTime事件时间&#xff08;一般流处理都会有两个时间&#xff1a;事件发生的事件&am…

Python_爬虫1_Requests库入门

目录 Requests库 7个主要方法 Requests库的get()方法 Response对象的属性 爬取网页的通用代码框架 理解requests库的异常 HTTP协议及Requests库方法 HTTP协议 HTTP协议采用URL作为定位网络资源的标识。 HTTP协议对资源的操作 理解PATCH和PUT的区别 HTTP协议与Requse…

万字长文解读深度学习——生成对抗网络GAN

&#x1f33a;历史文章列表&#x1f33a; 深度学习——优化算法、激活函数、归一化、正则化深度学习——权重初始化、评估指标、梯度消失和梯度爆炸深度学习——前向传播与反向传播、神经网络&#xff08;前馈神经网络与反馈神经网络&#xff09;、常见算法概要汇总万字长文解读…

学SQL,要安装什么软件?

先上结论&#xff0c;推荐MySQLDbeaver的组合。 学SQL需要安装软件吗&#xff1f; 记得几年前我学习SQL的时候&#xff0c;以为像Java、Python一样需要安装SQL软件包&#xff0c;后来知道并没有所谓SQL软件&#xff0c;因为SQL是一种查询语言&#xff0c;它用来对数据库进行操…

Leecode刷题C语言之统计好节点的数目

执行结果:通过 执行用时和内存消耗如下&#xff1a; 题目&#xff1a;统计好节点的数目 现有一棵 无向 树&#xff0c;树中包含 n 个节点&#xff0c;按从 0 到 n - 1 标记。树的根节点是节点 0 。给你一个长度为 n - 1 的二维整数数组 edges&#xff0c;其中 edges[i] [ai,…

【代码审计】常见漏洞专项审计-业务逻辑漏洞审计

❤️博客主页&#xff1a; iknow181 &#x1f525;系列专栏&#xff1a; 网络安全、 Python、JavaSE、JavaWeb、CCNP &#x1f389;欢迎大家点赞&#x1f44d;收藏⭐评论✍ 0x01 漏洞介绍 1、 原理 业务逻辑漏洞是一类特殊的安全漏洞&#xff0c;业务逻辑漏洞属于设计漏洞而非实…

【408】SDN重点笔记

总特征&#xff1a;数据平面&#xff08;负责转发&#xff09;与控制平面&#xff08;负责控制&#xff09;分离 控制平面&#xff1a; 由服务器和软件组成。控制平面完成转发表&#xff0c;并分发。 路由器不再需要路由选择协议&#xff0c;不再交换信息&#xff0c;只负责收到…

Redis的Zset在排行榜中应用

1.在pom文件导入&#xff1a; <!-- redis --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency><dependency><groupId>org.springframew…

安全见闻1-5

涵盖了编程语言、软件程序类型、操作系统、网络通讯、硬件设备、web前后端、脚本语言、病毒种类、服务器程序、人工智能等基本知识&#xff0c;有助于全面了解计算机科学和网络技术的各个方面。 安全见闻1 1.编程语言简要概述 C语言&#xff1a;面向过程&#xff0c;适用于系统…

入门车载以太网(4) -- 传输层(TCP\UDP)

目录 1.ECU通信方式的变化 2.传输层概述 2.1 UDP 2.2 TCP 3. TCP和ISO 15765-2 1.ECU通信方式的变化 我们先回顾下两种通信方式&#xff1a;Signal-Based Messaging、Service-Based Messaging。 Signal-Based Messaging 基于信号的通信方式&#xff0c;例如CAN通信&…

Tofu AI视频处理模块视频输入配置方法

应用Tofu产品对网络视频进行获取做视频处理时&#xff0c;首先需要配置Tofu产品的硬件连接关系与设备IP地址、视频拉流地址。 步骤1 Tofu设备点对点直连或者通过交换机连接到电脑&#xff0c;电脑IP配置到与Tofu默认IP地址同一个网段。 打开软件 点击右上角系统设置 单击左侧…

QT<30> Qt中使鼠标变为转圈忙状态

前言&#xff1a;当我们在写软件时&#xff0c;在等待阻塞耗时操作时可以将鼠标变为忙状态&#xff0c;并在一段时间后恢复状态&#xff0c;可以用到GxtWaitCursor&#xff1a;Qt下基于RAII的鼠标等待光标类。 一、效果演示 二、详细代码 在项目中添加C文件&#xff0c;命名为…

什么是CRM系统?

越来越多的企业意识到&#xff1a;如何有效管理与客户的关系、提升客户满意度&#xff0c;并通过这些提升推动销售增长&#xff0c;已经成为许多公司亟待解决的问题。为此&#xff0c;客户关系管理&#xff08;Customer Relationship Management&#xff0c;简称CRM&#xff09…