1) balance enquiry
2) deposit
3) withdraw
4) view details
A)
A)
Account |
accno name balance type |
getbalance() Deposit() Withdraw() Viewaccountdetails() |
Account is class name
accno , name , balance , type are Properties(general terminology) / attributes (UML terminology) / instance variables (java terminology)
Instance methods (java terminology) / operations (UML terminology) /behavior
// save as ExecuteAccount.java
//Execute account
class account {
int accno;
String name;
float balance;
String type;
void storeaccountdetails()
{
accno=1001;
name="krishna";
balance=8000;
type="savings";
}
float getbalance()
{
return balance;
}
void viewaccountdetails()
{
System.out.println("account :"+accno);
System.out.println("A/c holder name :"+name);
System.out.println("Balance (Rs) :"+balance);
System.out.println("A/c type :"+type);
}
void deposit(float amt)
{
balance = balance+amt;
}
void withdraw(float amt)
{
if(balance>amt)
{
balance= balance-amt;
System.out.println("please collect Rs :"+amt);
}
else
System.out.println("can't withdraw. Insufficient funds");
}
}
class ExecuteAccount
{
public static void main(String[] args) {
account acc= new account();
acc.storeaccountdetails();
acc.viewaccountdetails();
acc.deposit(40000);
acc.withdraw(15000);
float bal = acc.getbalance();
System.out.println("A/c balance is (Rs) :"+bal);
acc.withdraw(12000);
}
}
Output :
account :1001
A/c holder name :krishna
Balance (Rs) :8000.0
A/c type :savings
please collect Rs :15000.0
A/c balance is (Rs) :33000.0
please collect Rs :12000.0
Comments
Post a Comment