We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3da52e6 commit f4a04c7Copy full SHA for f4a04c7
Expense Tracker.java
@@ -0,0 +1,27 @@
1
+import java.util.*;
2
+
3
+public class ExpenseTracker {
4
+ public static void main(String[] args) {
5
+ HashMap<String, Integer> map = new HashMap<>();
6
+ Scanner sc = new Scanner(System.in);
7
8
+ while (true) {
9
+ System.out.println("1.Add Expense 2.View 3.Exit");
10
+ int ch = sc.nextInt();
11
+ sc.nextLine();
12
13
+ if (ch == 1) {
14
+ System.out.print("Category: ");
15
+ String c = sc.nextLine();
16
+ System.out.print("Amount: ");
17
+ int a = sc.nextInt();
18
+ map.put(c, map.getOrDefault(c, 0) + a);
19
+ }
20
+ else if (ch == 2) {
21
+ for (String k : map.keySet())
22
+ System.out.println(k + ": " + map.get(k));
23
24
+ else break;
25
26
27
+}
0 commit comments