-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExpense Tracker.java
More file actions
27 lines (24 loc) · 817 Bytes
/
Expense Tracker.java
File metadata and controls
27 lines (24 loc) · 817 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
import java.util.*;
public class ExpenseTracker {
public static void main(String[] args) {
HashMap<String, Integer> map = new HashMap<>();
Scanner sc = new Scanner(System.in);
while (true) {
System.out.println("1.Add Expense 2.View 3.Exit");
int ch = sc.nextInt();
sc.nextLine();
if (ch == 1) {
System.out.print("Category: ");
String c = sc.nextLine();
System.out.print("Amount: ");
int a = sc.nextInt();
map.put(c, map.getOrDefault(c, 0) + a);
}
else if (ch == 2) {
for (String k : map.keySet())
System.out.println(k + ": " + map.get(k));
}
else break;
}
}
}