Hello,
Try the following code, this may help you
Code:
Public class account
{
private float bal;
private static float numcp =0;
/ / numcp is initialized to zero, it is common to all classes and for each instantiation it will change in value since it is incremented.
Public account()
{numcp + +;}
/ / The first account will be number 1
/ / default bal will be initialized to zero.
Public void credit(float amount)
{bal + = amount;}
Public void charge(float amount)
{bal-= amount;}
Public float getSolde()
{return(bal);}
/ / accessor method for reading
Public void display()
{System.out.System.out.println("account number"+ + numcp"The bal is"+ bal +"Dinars");}}
Public class TestBanque
{Public static void hand (String [] args)
{Account acc =new account();
/ / Instance 1 will account number 1 and a bal of 0.
acc.credit(1000);
acc.dbitrate(500);
acc.display();
account = acc2 new account();
/ / instance 2 will have the account number 2 and a bal of 0.
acc2.credit(5000);
acc2.dbitrate(250);
acc2.display();
}
}
Bookmarks