import javax.swing.*;

public class bank_account
{
 private String name;
 private int account_number;
 private String password;
 private int password_trial;
 private static int maximum_password_trial=3;
 private double account_balance;
 public bank_account(String iname,int i_account_number,String i_password,double pgir)
 {name=iname;
  account_number=i_account_number;
  password=i_password;
  account_balance=pgir;
  password_trial=0;
 }
 
 public String read_account()
 { String s1="null";
   String password_read;
   int account_number_read=Integer.parseInt(JOptionPane.showInputDialog("account number = "));
   while(password_trial<maximum_password_trial)
   {
   password_read=JOptionPane.showInputDialog("password = ");   
   if(password_read.equals(password) ){password_trial=0;return write();}
   else{password_trial++;JOptionPane.showMessageDialog(null,"sorry wrong password, please try again","Wrong password",JOptionPane.PLAIN_MESSAGE);}
   }
   return s1;
 }
 
 public String change_password()
 {String s1="change password";
  String password_read;
  while(password_trial<maximum_password_trial)
  {
  password_read=JOptionPane.showInputDialog("password = ");	  
  if(password_read.equals(password) )
  {
	  String newpassword1=JOptionPane.showInputDialog("write your new password  = ");
	  String newpassword2=JOptionPane.showInputDialog("re-write your new password  = ");
	  if(newpassword1.equals(newpassword2))
	  {password=newpassword2;s1="Password is changed sucsessfully";break;}
	  else
	  {JOptionPane.showMessageDialog(null,"new password1 and new password2 is not the same","wrong new password",JOptionPane.PLAIN_MESSAGE);s1="Password change failuare";}
      password_trial=0;
  }
  else
  {JOptionPane.showMessageDialog(null,"sorry, wrong password please give it again","Wrong password",JOptionPane.PLAIN_MESSAGE);
  password_trial++;s1="Password change failure";
  }
 }
 return s1;
 }
 
 private String write()
 {String s="Account name = "+name+"\n";
  s+="Account number = "+account_number+"\n";
  s+="Account balance = "+account_balance+" T.L.\n"; 
  return s; 
 }
 
}