forked from krishna-verma/Java-Projects-Collections
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExpenseTracker.java
More file actions
52 lines (46 loc) · 1.74 KB
/
Copy pathExpenseTracker.java
File metadata and controls
52 lines (46 loc) · 1.74 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
// hi this is kanchan feel free to connect , code, friends, help . kanchankapri9github.io
import java.util.*;
class Expense {
String category;
double amount;
Expense(String category, double amount) {
this.category = category;
this.amount = amount;
}
}
public class ExpenseTracker { // here is the main
public static void main(String[] args) {
ArrayList<Expense> expenses = new ArrayList<>();
Scanner sc = new Scanner(System.in);
while (true) {
System.out.println("\n1. Add Expense\n2. View All\n3. Total Expense\n4. Exit");
System.out.print("Enter choice: ");
int ch = sc.nextInt();
switch (ch) {
case 1:
System.out.print("Enter category: ");
sc.nextLine();
String cat = sc.nextLine();
System.out.print("Enter amount: ");
double amt = sc.nextDouble();
expenses.add(new Expense(cat, amt));
break;
case 2:
System.out.println("Expenses List:");
for (Expense e : expenses)
System.out.println(e.category + " - ₹" + e.amount);
break;
case 3:
double total = 0;
for (Expense e : expenses) total += e.amount;
System.out.println("Total Expense: ₹" + total);
break;
case 4:
System.out.println("Goodbye!");
return;
}
}
}
}
// You can add more functionalities.........
// happy copsing :)