Thursday 16 February 2017

wap to create a class with following details: variables accno,name,address,type and bal methods: Withdrawal(),deposit(),display().Use constructors to initialize members

class account
{
String name,address,type;
int accno,bal;
account(String n,int no,int b)
{
name=n; accno=no; bal=b;
}
account(String n,int no,String addr,String t,int b)
{
name=n;
accno=no;
address=addr;
type=t;
bal=b;
}
void deposite(int a) {
bal+=a;
}
void withdraw(int a) {
bal-=a;
}
int getbalance() {
return(bal);
}
void show()
{
System.out.println("________________________");
System.out.println(" ACCOUNT DETAILS");
System.out.println("Name : "+name);
System.out.println("Account No : "+accno);
System.out.println("Address : "+address);
System.out.println("Type : "+type);
System.out.println("Balance : "+bal);

}


public static void main(String arg[])
{
account a1=new account("ayush",1,5000);
account a2=new account("varun",2,"india","Saving account",1000);
a1.address="india";
a1.type="Saving account";
a1.deposite(500);
a2.withdraw(100);
a2.deposite(a2.getbalance());
a1.show();
a2.show();
}
}

No comments:

Post a Comment