Program to represent Bank Account- Using Constructor
import java.io.DataInputStream; // to load DataInputStream class
class Bank
{
String name,type;
int acno,bal,wit,dep;
// To assign initial values by constructor
Bank(String n, String t,int b)
{
name=n;
type=t;
bal=b;
}
// To deposit an amount
void deposit()
{
//creating object of class DataInputStream.
DataInputStream in = new DataInputStream(System.in);
try
{
System.out.print(" Enter amt to deposit : ");
dep = Integer.parseInt(in.readLine());
bal=bal+dep;
show();
}
catch(Exception e) { System.out.println("I/O Error"); }
}
// To withdraw an amount after checking balance
void withdraw()
{
//creating object of class DataInputStream.
DataInputStream in = new DataInputStream(System.in);
try
{
System.out.println("\nEnter amt to withdraw : ");
wit = Integer.parseInt(in.readLine());
if(bal-wit>=500)
bal=bal-wit;
else
System.out.println("You cannot withdraw....");
show();
}
catch(Exception e) { System.out.println("I/O Error"); }
}
// To display the name and balance
void show()
{
System.out.println("\nDepositor name :"+name);
System.out.println("Type of Account :"+type);
System.out.println("Balance :"+bal);
}
}
class P25
{
public static void main(String args[ ])
{
int choice;
int ans;
Bank b1=new Bank("Stavan","Saving",50000); //providing initial value by constructor
b1.show();
//creating object of class DataInputStream.
DataInputStream in = new DataInputStream(System.in);
try
{
do
{
System.out.println("\n1. Deposit");
System.out.println("2. Withdraw");
System.out.print("Enter your choice (1/2) :");
choice = Integer.parseInt(in.readLine());
if(choice ==1)
b1.deposit();
if(choice ==2)
b1.withdraw();
System.out.println("\nDo you want to continue ?(1: yes /0 : No)");
ans = Integer.parseInt(in.readLine());
}while(ans==1);
}
catch(Exception e) { System.out.println("I/O Error"); }
}
}
import java.io.DataInputStream; // to load DataInputStream class
class Bank
{
String name,type;
int acno,bal,wit,dep;
// To assign initial values by constructor
Bank(String n, String t,int b)
{
name=n;
type=t;
bal=b;
}
// To deposit an amount
void deposit()
{
//creating object of class DataInputStream.
DataInputStream in = new DataInputStream(System.in);
try
{
System.out.print(" Enter amt to deposit : ");
dep = Integer.parseInt(in.readLine());
bal=bal+dep;
show();
}
catch(Exception e) { System.out.println("I/O Error"); }
}
// To withdraw an amount after checking balance
void withdraw()
{
//creating object of class DataInputStream.
DataInputStream in = new DataInputStream(System.in);
try
{
System.out.println("\nEnter amt to withdraw : ");
wit = Integer.parseInt(in.readLine());
if(bal-wit>=500)
bal=bal-wit;
else
System.out.println("You cannot withdraw....");
show();
}
catch(Exception e) { System.out.println("I/O Error"); }
}
// To display the name and balance
void show()
{
System.out.println("\nDepositor name :"+name);
System.out.println("Type of Account :"+type);
System.out.println("Balance :"+bal);
}
}
class P25
{
public static void main(String args[ ])
{
int choice;
int ans;
Bank b1=new Bank("Stavan","Saving",50000); //providing initial value by constructor
b1.show();
//creating object of class DataInputStream.
DataInputStream in = new DataInputStream(System.in);
try
{
do
{
System.out.println("\n1. Deposit");
System.out.println("2. Withdraw");
System.out.print("Enter your choice (1/2) :");
choice = Integer.parseInt(in.readLine());
if(choice ==1)
b1.deposit();
if(choice ==2)
b1.withdraw();
System.out.println("\nDo you want to continue ?(1: yes /0 : No)");
ans = Integer.parseInt(in.readLine());
}while(ans==1);
}
catch(Exception e) { System.out.println("I/O Error"); }
}
}
3 comments:
x8m33j5z98 z7w00i9f63 e4m78z4d87 w0x48d8l76 u7y92g7n80 x8i03b2e66
o1u87p9u04 p1p74t2c17 v6p99u9z61 k7l54z3y66 m5g29w9s11 j3l50k0s26
off white outlet
stephen curry shoes
yeezy gap hoodie
pg 4
ggdb
off white hoodie outlet
goyard store
kyrie irving
hermes outlet
off white nike
Post a Comment