Using Java to simulate a bank account storage System

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];
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.