Using Java to simulate a bank account storage System
Last Update:2018-07-26
Source: Internet
Author: User
Package cn.mdln.study2;
/**
* Simulate bank Account storage System
* @author Administrator
*
*/
public class TestDemo16 {
public static void Main (string[] args) {
Accounts2 account1=new Accounts2 (500);
Accounts2 account2=new Accounts2 (600);
Accounts2 account3=new Accounts2 (700);
Customer2 customer1=new Customer2 ("Smith", "12345", "13075325795");
Customer2 customer2=new Customer2 ("Lucyy", "A1B2C", "23075325795");
Customer2 customer3=new Customer2 ("Bobye", "se875", "33075325795");
Bank Band=new Bank ();
Band.addcustome (Customer1);
Band.addcustome (CUSTOMER2);
Band.addcustome (CUSTOMER3);
Customer1.setaccounts (ACCOUNT1);
Customer2.setaccounts (Account2);
Customer3.setaccounts (ACCOUNT3);
for (int x=0;x<band.getnumberofcustomer (); x + +)
{
System.out.println ("index[" +x+ "]=" +band.getcustomer2 (x));
}
for (int x=0;x<band.getnumberofcustomer (); x + +)
{
System.out.println ("Your deposit amount is:" +band.getcustomer2 (x). Getaccounts (). Getbanlance ());
SYSTEM.OUT.PRINTLN ("Transaction success:" +band.getcustomer2 (x). Getaccounts (). Withdraw (150));
System.out.println (Band.getcustomer2 (x). toString () + "Current amount available for your account:" +band.getcustomer2 (x). Getaccounts (). Getbanlance ());
SYSTEM.OUT.PRINTLN ("Transaction success:" +band.getcustomer2 (x). getaccounts (). Deposit (22.5));;
System.out.println (Band.getcustomer2 (x). toString () + "Current amount available for your account:" +band.getcustomer2 (x). Getaccounts (). Getbanlance ());
SYSTEM.OUT.PRINTLN ("Transaction success:" +band.getcustomer2 (x). Getaccounts (). Withdraw (47.62));
System.out.println (Band.getcustomer2 (x). toString () + "Current amount available for your account:" +band.getcustomer2 (x). Getaccounts (). Getbanlance ());
}
}
}
Class accounts2//Account
{
Private double balance;//account balance
Public Accounts2 (double balance)
{
This.balance=balance;
}
Public double getbanlance ()//Get account balance
{
return this.balance;
}
Public Boolean deposit (double)/Save
{
This.balance+=money;
return true;
}
Public Boolean withdraw (double)//Withdraw money
{
if (This.balance<money)
{
SYSTEM.OUT.PRINTLN ("Insufficient balance");
return false;
}
Else
{
This.balance-=money;
return true;
}
}
}
Class customer2//a user
{
Private String name;//User name
Private String idcard;//User identification number
Private String phone;//User Contact
Private Accounts2 account;//class is a combined relationship with a class
Public Customer2 (String name,string idcard,string phone)
{
This.name=name;
This.idcard=idcard;
This.phone=phone;
}
Public String GetName ()
{
return this.name;
}
Public String toString ()
{
Return "\ t username:" +this.name+ "\n\t ID Number:" +this.idcard+ "\n\t Contact:" +this.phone+ "\ n";
}
Public Accounts2 getaccounts ()
{
return this.account;
}
public void Setaccounts (ACCOUNTS2 account)
{
This.account=account;
}
}
Class bank//a Bank
{
Private customer2[] customer;//Bank has multiple users
private static int count=0;
Public Bank ()
{
Customer=new CUSTOMER2[10];
}
public void Addcustome (Customer2 customer)
{
This.customer[count++]=customer;
}
@SuppressWarnings ("Static-access")
public int Getnumberofcustomer ()
{
return this.count;
}
Public Customer2 getCustomer2 (int index)
{
return This.customer[index];
}
}