-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path15.1 Net Banking.java
More file actions
75 lines (61 loc) · 2.25 KB
/
15.1 Net Banking.java
File metadata and controls
75 lines (61 loc) · 2.25 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
/*
Peter logins into his banking application to perform certain transaction. Initially he is asked to enter his present balance. Then he is shown three options to choose from, where he is asked to choose 1 for withdrawal and 2 for deposit and 3 to check the balance. On choosing 1, he is prompted to enter amount to be withdrawn. In case if the amount entered is greater than his present balance, "error" should be displayed, the account balance should be updated otherwise. On choosing 2, he is prompted to enter amount to be deposited and the account balance should be updated. Choosing 3 should display the balance. Choosing any other option should display "error".
Input Format
10000.20
2
200.50
Constraints
The balance and amount are to be taken as float type numbers. The output displayed too is a floating point number.
Output Format
10200.70
Sample Input 0
20000.20
1
100.00
Sample Output 0
19900.20
*/
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc = new Scanner(System.in);
float Balance = sc.nextFloat();
int choice = sc.nextInt();
switch(choice)
{
case 1:
{
float withdrawn = sc.nextFloat();
if(withdrawn>Balance)
{
System.out.print("error");
}
else
{
Balance -= withdrawn;
System.out.printf("%.2f",Balance);
}
break;
}
case 2:
{
float deposited = sc.nextFloat();
Balance += deposited;
System.out.printf("%.2f",Balance);
break;
}
case 3:
{
System.out.printf("%.2f",Balance);
break;
}
default:
{
System.out.print("error");
break;
}
}
}
}