-
Notifications
You must be signed in to change notification settings - Fork 296
Expand file tree
/
Copy pathbank_account.java
More file actions
82 lines (78 loc) · 2.02 KB
/
bank_account.java
File metadata and controls
82 lines (78 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*Design and write a class to represent a bank account that includes the following members:
a. Data members
· Owner name
· Account number
· Balance amount in the account
b. Methods members
· To assign initial values
· To deposit an amount
· To withdraw an amount after checking balance
· To display the owner name and balance*/
import java.util.Scanner;
public class BankAccount1
{
int acc_no;
String name;
float bal,amt,withdraw;
Scanner A=new Scanner(System.in);
void read()
{
System.out.println("Enter Owner's Name: ");
name=A.next();
System.out.println("Enter Account Number: ");
acc_no=A.nextInt();
}
void deposit()
{
int choice;
float current,saving;
Scanner A=new Scanner(System.in);
System.out.println("Enter Initial Amount: ");
amt=A.nextFloat();
System.out.println("1.Savings Account");
System.out.println("2.Current Account");
System.out.println("Enter Choice: ");
choice=A.nextInt();
switch(choice)
{
case 1:
saving=amt;
System.out.println("Amount In Savings Account Is: "+saving);
break;
case 2:
current=amt;
System.out.println("Amount In Savings Account Is: "+current);
break;
default:
break;
}
}
void withdraw()
{
Scanner A=new Scanner(System.in);
System.out.println("Enter Withdrawal Amount: ");
withdraw=A.nextFloat();
bal=amt-withdraw;
amt=bal;
if(bal>0)
{
System.out.println("Balance Amount Left Is :"+bal);
}
else
{
System.out.println("Zero Balance");
}
}
void display()
{
System.out.println("Owner's Name Is: "+name);
System.out.println("Balance Left In Bank Is: "+bal);
}
public static void main(String[] args) {
BankAccount1 B1=new BankAccount1();
B1.read();
B1.deposit();
B1.withdraw();
B1.display();
}
}