import java.util.Scanner;

public class TestTP11
{
	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		Administrator administrator1 = new Administrator();
		administrator1.userName = "admin1";
		administrator1.password = "12345";
		administrator1.showInfo();

		Administrator administrator2 = new Administrator();
		administrator2.userName = "admin2";
		administrator2.password = "54321";
		administrator2.showInfo();
		System.out.println("是否需要修改密码？(y/n):");
		String answer = sc.next();
		if("y".equals(answer))
		{
			System.out.println("请选择要修改密码的账户1.admin1\t2.admin2");
			int choice = sc.nextInt();
			switch(choice)
			{
				case 1:
					administrator1.changePassword();
					break;
				case 2:
					administrator2.changePassword();
					break;
			}
		}
		else
		{
			System.out.println("程序结束");
		}
		sc.close();
	}
}
		
class Administrator
{
	
	String userName;
	String password;
	public void showInfo()
	{
		System.out.println("姓名：" + userName + "\n密码：" + password);
	}
	public void changePassword()
	{
		Scanner sc = new Scanner(System.in);
		System.out.println("先登录再修改密码。\n请输入帐号：");
		String inputName = sc.next();
		System.out.println("请输入密码：");
		String inputPassword = sc.next();	
		Boolean judge = true;
		if(this.userName.equals(inputName) && this.password.equals(inputPassword))
		{		
			while(judge)
			{
				System.out.println("登录成功\n请输入新密码：");
				String newPassword = sc.next();
				System.out.println("修改成功，你的新密码是：" + newPassword);
				System.out.println("请重新登录：");
				System.out.println("请输入帐号：");
				userName = sc.next();
				System.out.println("请输入密码：");
				password = sc.next();			
				while(judge)
				{
					if(this.userName.equals(userName) && newPassword.equals(password))
					{
						System.out.println("登录成功!你的新密码是：" + password);
						judge = false;
					}	
					else
					{
						System.out.println("帐号密码不匹配,请重新登录。");
						System.out.println("请输入帐号：");
						userName = sc.next();
						System.out.println("请输入密码：");
						password = sc.next();
					}
				}
			}	
		}

		else
		{
			System.out.println("帐号密码错误，你没有权限修改密码！");	
		}
		sc.close();
	}
}