Sunday, January 12, 2014

Object Oriented Programming Example in Java[Simple]

class Bank{
//Data Members
String cust_name;
int accno;
String type;
float balance;

//assigning initial values
void setvalue(String n,int a,String t,float b){
cust_name =n;
accno =a;
type=t;
balance = b;
}

//Deposit amount
void deposit(float d){
balance = balance + d;
}

//withdraw amount
void withdraw(float w){
if(balance >= w){
balance = balance - w;
}
else{
System.out.println("Insufficent balance");
}
}
//Displaying the details
void display(){
System.out.println("Name = "+cust_name);
System.out.println("Balance = Rs"+balance);
}

public static void main(String args[]){
//customer1
Bank b1 = new Bank();
b1.setvalue("Ram",293843,"saving",500);
b1.deposit(2000);
b1.withdraw(1000);
b1.display();
//customer2
Bank b2 = new Bank();
b2.setvalue("Saravanan",293844,"saving",500);
b2.deposit(2300);
b2.withdraw(1500);
b2.display();

}
}



Post a Comment