-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmartExpenseTracker.java
More file actions
65 lines (65 loc) · 2.74 KB
/
SmartExpenseTracker.java
File metadata and controls
65 lines (65 loc) · 2.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.util.Scanner;
class SmartExpenseTracker {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int select;
int totalExpense = 0;
int foodExpense = 0;
int travelExpense = 0;
int otherExpense = 0;
System.out.print("Enter your daily expense limit: ");
int limit = sc.nextInt();
while (true) {
System.out.println("\n--- Smart Expense Tracker ---");
System.out.println("1. Add Expense");
System.out.println("2. Show Summary");
System.out.println("3. Exit");
System.out.print("Enter your selected number: ");
select = sc.nextInt();
switch (select) {
case 1:
sc.nextLine();
System.out.print("Enter category (food/travel/other): ");
String category = sc.nextLine().toLowerCase();
System.out.print("Enter expense amount: ");
int amt = sc.nextInt();
if (amt <= 0) {
System.out.println("Invalid amount. Please enter a positive value.");
break;
}
totalExpense += amt;
if (category.equals("food")) {
foodExpense += amt;
} else if (category.equals("travel")) {
travelExpense += amt;
} else if (category.equals("other")) {
otherExpense += amt;
} else {
System.out.println("Invalid category! Expense added to 'Other'.");
otherExpense += amt;
}
System.out.println("Expense added successfully!");
if (totalExpense > limit) {
System.out.println(" WARNING: You crossed your daily limit!");
}
break;
case 2:
System.out.println("\n--- Expense Summary ---");
System.out.println("Food Expense : " + foodExpense);
System.out.println("Travel Expense : " + travelExpense);
System.out.println("Other Expense : " + otherExpense);
System.out.println("-------------------------");
System.out.println("Total Expense : " + totalExpense);
System.out.println("Daily Limit : " + limit);
break;
case 3:
System.out.println("\nFinal Summary:");
System.out.println("Total Spent: " + totalExpense);
System.out.println("Thank you for using Smart Expense Tracker!");
return;
default:
System.out.println("Invalid choice. Try again.");
}
}
}
}