import javax.swing.*;

public class Bank
{

	  static int index,addc=0;

 	  static String name[]=new String[100];
      static String pass[]=new String[100];
      static double balance[]=new double[100];


      public int search(String target)
	        { //search

	            for (int x=0; x<name.length ; x++)
				        if(target.equals(name[x]))
				           return x;

                           return -1;

			} // end search method




	public void bank()
		{  //bank method
			String s1 = JOptionPane.showInputDialog(null," 1- ATM \n 2- Bank User \n 3- exit ");
			int option1 = Integer.parseInt(s1);
			switch (option1)
			{   //switch
				case 1:
				       ATM();
				break;

				case 2:
				       bank_user();
                break;

                case 3:
				       System.exit(0);
     			break;


		    } //end switch
        } // end bank method




    public void addCustomer()
    { // method add ccustomer

         String name1=JOptionPane.showInputDialog(null,"Enter your name to creat account: ");
		 index = search(name1);
		 if (index == -1)
		 { // if
		     name[addc]=name1;
		     pass[addc]=JOptionPane.showInputDialog(null,"Enter your password to creat account: ");
		 	 String b=JOptionPane.showInputDialog(null,"Enter your balance to creat account: ");
		 	 balance[addc]=Double.parseDouble(b);

		 	 JOptionPane.showMessageDialog(null,"add  successfull.... ");
		 	 JOptionPane.showMessageDialog(null,"Name     Password     Balance\n"+name[addc]+"     "+pass[addc]+"         "+balance[addc]);
		 	 addc++;
	     } // end if

		 else
		     JOptionPane.showMessageDialog(null," sorry this name of customer is registry....");

    } // end method addCustomer


    public void manageCustomer()
    { // method manageCustomer

       String s3 = JOptionPane.showInputDialog(null," 1- delete custmer \n 2- Edit customer \n 3- back ");
	   int managList = Integer.parseInt(s3);

	   switch (managList)
	   {   //switch
	       case 1: //delete custmer
                     deleteCustomer();
                     manageCustomer();
	       break;

	       case 2: //Edit customer
                     editeCustomer();
                     manageCustomer();
	       break;

	       case 3: // back
                      bank_user();
	       break;
	  }// end switch


    } // end method manageCustomer



    public void deleteCustomer()
    { // method deleteCustomer

       String delcustomer=JOptionPane.showInputDialog(null,"enter the name of account to delete: ");
	   index = search(delcustomer);
	   if (index == -1)
	       JOptionPane.showMessageDialog(null,"sorry this name is not found... ");

	   else
	   { // else
	   	   name[index]=null;
	   	   pass[index]=null;
	       balance[index]=0;
	   	   JOptionPane.showMessageDialog(null,"delete successfull.... ");
	   } // end ielse

    } // end method deleteCustomer




	public void editeCustomer()
	{ // method editeCustomer

       String edit=JOptionPane.showInputDialog(null,"Enter the name of account to edit: ");
	   index = search(edit);
	   if (index == -1)
	       JOptionPane.showMessageDialog(null,"sorry this name to edite is not found... ");

	   else
	   { // else
	   	   name[index]=JOptionPane.showInputDialog(null,"enter the new name of your account: ");
	   	   pass[index]=JOptionPane.showInputDialog(null,"enter the new password of your account: ");
	   	   String new_b=JOptionPane.showInputDialog(null,"enter the new balance of your account: ");
	   	   balance[index]=Double.parseDouble(new_b);
	   	   JOptionPane.showMessageDialog(null,"edit successfull.... ");
	   	   JOptionPane.showMessageDialog(null,"Name     Password     Balance\n"+name[index]+"     "+pass[index]+"       "+balance[index]);
	   } // end else

     } // end method editeCustomer








    public void bank_user()
		{ //bank user

                    String s2 = JOptionPane.showInputDialog(null," 1- Add Customer \n 2- manage Customer \n 3- back ");
								int bankUserList = Integer.parseInt(s2);
								switch (bankUserList)
								{   //switch
			                        	case 1: // add customer
			                        	           addCustomer();
			                        	           bank_user();
                                        break;

                                        case 2: // manage customer
                                                   manageCustomer();
                                                   bank_user();
                                        break;

                                        case 3: // back
                                                   bank();
     			                        break;
							    }// end switch

		}// end bank_user method




    public  void ATM()
		{  // ATM method
		          	String name1="ali";
					String pass1="ali";
					double bal1=1000;

					String name2="omer";
					String pass2="omer";
					double bal2=2000;

					String name3="ahmed";
					String pass3="ahmed";
					double bal3=3000;

					String username, userpass;
					username= JOptionPane.showInputDialog(null,"Welcome \n Enter the Account name");

					if(( username.equals(name1) || username.equals(name2) || username.equals(name3)) == false)
						JOptionPane.showMessageDialog(null," This Account not exist");
					else

					if(username.equals(name1))
					{ // if1
						userpass= JOptionPane.showInputDialog(null,"Welcome \n Enter the Account Password");
						if(userpass.equals(pass1))
						{
							JOptionPane.showMessageDialog(null," welcome  " + name1 + "  Your balance is " + bal1);
							//obj.
							manage_balance(name1, bal1);
						}
						else
							JOptionPane.showMessageDialog(null," Sorry ..  wrong password");
					} // end if1

					else
					if(username.equals(name2))
					{ // if2
								userpass= JOptionPane.showInputDialog(null,"Welcome \n Enter the Account Password");
								if(userpass.equals(pass2))
								{
									JOptionPane.showMessageDialog(null," welcome " + name2 + "Your balance is " + bal2);
									//obj.
									manage_balance(name2, bal2);
								}

								else
									JOptionPane.showMessageDialog(null," Sorry ..  wrong password");
					} // end if2
					else
					if(username.equals(name3))
							{ // if3
								userpass= JOptionPane.showInputDialog(null,"Enter the Account Password");
								if(userpass.equals(pass3))
								{
									JOptionPane.showMessageDialog(null," welcome " + name3 + "Your balance is " + bal3);
									//obj.
									manage_balance(name3, bal3);
								}

								else
									JOptionPane.showMessageDialog(null," Sorry ..  wrong password");

					} // end if3
	}//end ATM method


	public void manage_balance(String name, double bal)
	{ // manage_balance method
		String s = JOptionPane.showInputDialog(" 1- balance \n 2- deposite \n 3- withdraw  \n 4- exit");
		int option = Integer.parseInt(s);

		switch(option)
		{// switch
			case 1:
				    JOptionPane.showMessageDialog(null," your balance is " + bal);
				    manage_balance(name,bal);
				    break;

			case 2:
					double amount1 = Double.parseDouble(JOptionPane.showInputDialog(null,"Enter the amount"));
					bal+=amount1;
					JOptionPane.showMessageDialog(null,"Successfull.. your new balance is " + bal);
					manage_balance(name,bal);
					break;

			case 3:
					double amount2 = Double.parseDouble(	JOptionPane.showInputDialog(null,"Enter the amount"));
					bal-=amount2;
					JOptionPane.showMessageDialog(null,"Successfull.. your new balance is " + bal);
					manage_balance(name,bal);
					break;

			case 4:
     				System.exit(0);
     				break;



		} // end switch
	}//end manage_balance method


	public static void main(String args[])
	{// main

		Bank obj= new Bank();
        obj.bank();


	} // end main
} // end class





















