-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExp42.java
More file actions
43 lines (32 loc) · 881 Bytes
/
Exp42.java
File metadata and controls
43 lines (32 loc) · 881 Bytes
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
import java.util.Scanner;
class BankAccount{
private double balance;
public BankAccount(){
balance = 0.0;
}
public void addFund(){
Scanner s = new Scanner(System.in);
System.out.println("Enter amount to add: ");
double amount = s.nextDouble();
balance += amount;
System.out.println("\nAmount added: " + amount + "rs");
}
protected void deduct(){
Scanner s = new Scanner(System.in);
System.out.println("Enter amount to deduct: ");
double amount = s.nextDouble();
balance -= amount;
System.out.println("\nAmount deducted: " + amount + "rs");
}
void checkBalance(){
System.out.println("Your balance is: " + balance);
}
}
public class Exp42{
public static void main(String[] args){
BankAccount account = new BankAccount();
account.addFund();
account.deduct();
account.checkBalance();
}
}