import java.util.Scanner;
/**
* 采用面向對象的方式 寫一個登錄系統
* @author Administrator
*
*/
//用戶信息
class UserInfo{
public static String[] user = new String[10];
public static String[] passwd = new String[10];
public UserInfo() {
this.user[0] = "test";
this.passwd[0] ="123456";
}
}
//找回密碼
class ZhaoHui extends UserInfo{
public static void zhaohui() {
Scanner s = new Scanner(System.in);
System.out.println("請輸入你要找回的用戶名:");
String zname = s.nextLine();
for(int i=0;i<2;i++) {
if(user[i].equals(zname)) {
Scanner ss = new Scanner(System.in);
System.out.println("恭喜你!成功找回密碼,請輸入:"+"'張哥最帥'"+" 查看密碼");
String zgzs = ss.nextLine();
if("張哥最帥".equals(zgzs)) {
System.out.println(passwd[i]);
}else {
System.out.println("請輸正確!");
}
}else if(user[i]!=zname){
System.out.println("用戶名不存在!");
return;
}
break;
}
}
}
//修改密碼
class XiuGai extends UserInfo{
public static void xiugai() {
Scanner s =new Scanner(System.in);
System.out.println("請輸入您要修改的密碼:");
String xpasswd = s.nextLine();
for(int i=0;i<2;i++) {
passwd[i] = xpasswd;
if(xpasswd.equals(passwd[i])) {
System.out.println("恭喜你,修改成功!");
break;
}else {
System.out.println("修改密碼失敗");
break;
}
}
}
}
//查詢用戶
class ChaXun extends UserInfo{
public static void select() {
for(int i=0;i<2;i++) {
System.out.println("當前用戶:"+user[i] +"\n"+ "當前密碼:"+passwd[i] );
i++;
break;
}
}
}
//注冊
class ZhuCe extends UserInfo{
public static void regist() {
Scanner ss = new Scanner(System.in);
System.out.println("請輸入用戶名:");
String suser = ss.nextLine();
System.out.println("請輸入密碼:");
String spasswd = ss.nextLine();
for(int i=0;i<user.length;i++) {
user[i] = suser;
passwd[i] = spasswd;
System.out.println("注冊成功!");
break;
}
}
}
//登錄
class Loginc extends UserInfo{
public static void login() {
int flag = 1;
Scanner scanner = new Scanner(System.in);
System.out.println("請輸入用戶名:");
String users = scanner.nextLine();
System.out.println("請輸入密碼:");
String passwds = scanner.nextLine();
for(int i=0;i<UserInfo.user.length;i++) {
if(user[i].equals(users) && passwd[i].equals(passwds)) {
System.out.println("登陸成功!");
break;
}
System.out.println("登陸失敗!");
break;
}
}
}
//主界面
class ZhuJieMian{
public static void Start() {
Loginc Loginc = new Loginc();
ZhuCe ZhuCe = new ZhuCe();
ChaXun ChaXun = new ChaXun();
XiuGai XiuGai = new XiuGai();
ZhaoHui ZhaoHui = new ZhaoHui();
Scanner s = new Scanner(System.in);
while(true) {
System.out.println("|"+ "\t"+ "\t"+ "\t"+ "\t"+ "\t"+ "\t"+ "\t"+"\t"+"|");
System.out.println("|"+"\t" + "測試用戶名:test 測試密碼:123456" + "\t"+ "\t"+ "\t"+ "\t"+"|");
System.out.println("|" + "\t"+ "請輸入[1-5]進行操作 1.登錄|2.注冊|3.查詢當前用戶|4.修改密碼|5.找回密碼 " + "\t"+"|");
System.out.print("請輸入:");
int temp = s.nextInt();
switch(temp) {
case 1:Loginc.login();
break;
case 2:ZhuCe.regist();;
break;
case 3:ChaXun.select();;
break;
case 4:XiuGai.xiugai();;
break;
case 5:ZhaoHui.zhaohui();;
break;
default:System.out.println("錯誤!請重寫輸入正確的數字進行操作!");
}
}
}
}
public class LoginTest {
public static void main(String[] args) {
ZhuJieMian zjm = new ZhuJieMian();
zjm.Start();
}
}
運行結果: