-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathaccounts.java
60 lines (59 loc) · 1.73 KB
/
accounts.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
import java.util.*;
class accounts
{
int accno;
int balance=1000;
accounts(int acno)
{
accno=acno;
}
public void withdraw(int amt)
{
if(amt>=balance)
{
System.out.println("insufficient balance");
}
else
{
balance=balance-amt;
}
}
public void deposite(int amt)
{
if(amt<=0)
{
System.out.println("the minimum amount that can be deposited should be greater than 0");
}
else
{
balance=balance+amt;
}
}
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int amt;
System.out.println("enter the account number");
int acno=sc.nextInt();
accounts obj=new accounts(acno);
System.out.println("initial amount = "+(obj.balance));
System.out.println("Enter \n1 to deposite \n2 to make a withdraw");
int c=sc.nextInt();
switch(c)
{
case 1: System.out.println("enter the amount to be deposited");
amt=sc.nextInt();
obj.deposite(amt);
System.out.println("Account number "+obj.accno);
System.out.println("the final balance is "+obj.balance);
break;
case 2: System.out.println("enter the amount to be withdrawn");
amt=sc.nextInt();
obj.withdraw(amt);
System.out.println("Account number "+obj.accno);
System.out.println("the final balance is "+obj.balance);
break;
default: System.out.println("wrong input");
}
}
}