-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBankAccount.java
70 lines (60 loc) · 1.48 KB
/
BankAccount.java
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
// 16. Design a class to represent a bank account.
// Include the following members:
// Data members:
// Name of the depositor
// Account number
// Type of account
// Balance amount in the account.
// Methods:
// To assign initial values
// To deposit an amount
// To withdraw an amount after checking balance
// To display the name and balance
import java.util.Scanner;
class Bank{
String name ;
int accno;
String acctype;
double balance;
void initialize () {
name = "joe biden";
accno = 123456;
acctype = "Savings";
balance = 123.12;
}
void deposit(double deposit)
{
balance += deposit;
System.out.println("the available balance is : "+ balance);
}
void withdraw (double withdraw )
{
if (withdraw >= balance) {
System.out.println("Insufficient balance ");
}
else
{
balance -= withdraw;
System.out.println("the available balance is : "+ balance);
}
}
void display()
{
System.out.println("name: " + name);
System.out.println("the available balance is : " + balance);
}
}
public class BankAccount {
public static void main(String[] args) {
Bank ob = new Bank();
Scanner sc = new Scanner(System.in);
ob.initialize();
System.out.println("enter the deposit amount : ");
double deposit = sc.nextDouble();
ob.deposit(deposit);
System.out.println("enter the withdraw amount : ");
double withdraw = sc.nextDouble();
ob.withdraw(withdraw);
ob.display();
}
}