java账号密码管理
程序刚运行就会出现以下三个需求
注册账号: 可以多注册账号 最多注册五个 然后登陆的时候可以一一对应的上名字
登陆账号: 登陆的时候显示相对应的名字
查看所有账号:
登陆后才会出现以下的需求
修改账号密码: 正常修改 账号密码
认证账号密码: 必须使用18位数字来认证
查看当前账号状态
注销账号: 输入的账号必须是存在的,然后注销账号 把用户名显示已注销
package 账号密码管理;
import java.util.Scanner;
//注册账号: 可以多注册账号 最多注册五个 然后登陆的时候可以一一对应的上名字
//注销账号: 输入的账号必须是存在的,然后注销账号 把用户名显示已注销
//登陆账号: 登陆的时候显示相对应的名字
//修改账号密码: 正常修改 账号密码
//认证账号密码: 必须使用18位数字来认证
//查看当前账号状态
//查看所有账号:
public class Page {
public static void main(String[] args) {
Scanner input = new Scanner ( System.in );
//创建数组
String[] account = new String[5];//账号数组
String[] password = new String[5];//密码数组
String[] names = new String[5];//用户名数组
int[] condition = new int[5];//状态 0代表未认证
Boolean isSeek = false;
do {
System.out.println ("欢迎使用账号密码管理系统");
System.out.println ("1.注册账号\n2.登陆账号\n3.查看所有账号");
System.out.println ("请选择:");
switch(input.nextInt ()){
case 1:
isSeek = true;
System.out.println ("注册新的账号");
for (int i = 0; i < account.length; i++) {
if (account[i] == null){
System.out.println ("请输入用户名:");
names[i] = input.next ();
System.out.println ("请输入您的账号:");
account[i] = input.next();
while (account[i].length () != 9){
System.out.println ("账号的长度必须是9位数字");
account[i] = input.next();
if (account[i].length () == 9){
break;
}
}
System.out.println ("请输入您的密码:");
password[i] = input.next ();
condition[i] = 0;
System.out.println ("注册成功,恭喜"+names[i]+"用户");
break;
}
}
break;
case 2:
Boolean isCheck = false;
if (isSeek){
System.out.println ("欢迎登陆");
System.out.println ("请输入账号:");
String out = input.next ();
while (out.length () != 9){
System.out.println ("账号的长度必须是9位数字");
out = input.next ();
if (out.length () == 9){
break;
}
}
System.out.println ("请输入密码:");
String paw = input.next ();
for (int i = 0; i < account.length; i++) {
if (out.equals ( account[i] ) && paw.equals ( password[i] )){
isCheck = true;
System.out.println ("登陆成功!");
System.out.println ("请选择以下业务:");
do {
System.out.println ("1.查看账号的状态\n2,修改账号密码\n3.注销此账号\n4,认证账号密码");
System.out.println ("请选择需要的要求:");
switch (input.nextInt ()){
case 1:
System.out.println ("当前账号的状态");
String state = condition[i]==0?"未认证":"已实名";
System.out.println ("用户名:"+names[i]+"\t\t账号:"+account[i]+"\t\t密码"+password[i]+"\t\t"+state);
break;
case 2:
System.out.println ("修改账号或密码");
System.out.println ("1.修改账号\n2.修改密码");
switch (input.nextInt ()){
case 1:
System.out.println ("请输入原账号:");
String Original = input.next ();
if (Original.equals ( account[i] )){
System.out.println ("请输入新的账号:");
account[i] = input.next ();
System.out.println ("修改成功!");
}else {
System.out.println ("原账号不匹配!");
}
break;
case 2:
System.out.println ("请输入原密码:");
String word = input.next ();
if (word.equals ( password[i] )){
System.out.println ("请输入新的密码:");
password[i] = input.next ();
System.out.println ("修改成功!!");
}else {
System.out.println ("原密码不匹配!!!");
}
break;
default:
System.out.println ("只能修改这些!!");
}
break;
case 3:
int index = -1;
System.out.println ("注销此账号");
System.out.println ("请输入您要注销的账号:");
String number = input.next ();
if (number.equals ( account[i] )){
index = i;
}else {
System.out.println ("没有找到该账号,无法注销");
}
if (index != -1){
for (int j = index; j < account.length; j++) {
if (j != account.length-1){
account[j] = account[j+1];
password[j] = password[j+1];
names[j] = names[j+1];
condition[j] = condition[j+1];
break;
}
}
account[account.length-1] = null;
password[password.length-1] = null;
names[names.length-1] = null;
condition[condition.length-1] = 0;
System.out.println ("注销成功!!!");
}
break;
case 4:
System.out.println ("认证账号:");
System.out.println ("输入需要认证的账号:");
String bawl = input.next ();
if (bawl.equals ( account[i] )){
if (condition[i] != 1){
System.out.println ("请输入要认证的身份账号:");
String card = input.next ();
if (card.length () == 18){
condition[i] = 1;
}else {
System.out.println ("身份证位数长度不够");
}
}else {
System.out.println ("该账号已经认证!!");
}
}else {
System.out.println ("输入的账号 ,和原账号不匹配");
}
break;
default:
System.out.println ("敬请期待");
}
System.out.println ("输入y继续:");
}while (input.next ().charAt ( 0 ) == 'y');
System.out.println ("退出登陆成功!!");
break;
}
}
if (!isCheck){
System.out.println ("该账号不存在!(或账号密码错误)!!!");
}
}else {
System.out.println ("请先注册账号");
}
break;
case 3:
System.out.println ("参看所有账号");
for (int i = 0; i < account.length; i++) {
if (account[i] != null){
String state = condition[i]==0?"未认证":"已实名";
System.out.println ("用户名:"+names[i]+"\t\t账号:"+account[i]+"\t\t密码"+password[i]+"\t\t"+state);
}
}
break;
default:
System.out.println ("敬请期待");
}
System.out.println ("y继续输入:");
}while (input.next ().charAt ( 0 ) == 'y');
System.out.println ("退出成功!!!!");
}
}