import 'dart:io'; void main() { print("Welcome to the Budget Management Application!"); budgetManager(); } void budgetManager() { Map expenses = {}; double totalIncome = 0.0; while (true) { print("\nChoose an option:"); print("1. Add Income"); print("2. Add Expense"); print("3. View Summary"); print("4. Exit"); String? choice = stdin.readLineSync(); if (choice == "4") { print("Exiting the application."); break; } switch (choice) { case "1": print("Enter income amount:"); double? income = double.tryParse(stdin.readLineSync() ?? ""); if (income != null && income > 0) { totalIncome += income; print("Income added successfully."); } else { print("Invalid amount."); } break; case "2": print("Enter expense description:"); String? name = stdin.readLineSync(); print("Enter expense amount:"); double? amount = double.tryParse(stdin.readLineSync() ?? ""); if (name != null && amount != null && amount > 0) { expenses[name] = amount; print("Expense added successfully."); } else { print("Invalid input."); } break; case "3": showReport(totalIncome, expenses); break; default: print("Invalid option. Try again."); } } } void showReport(double income, Map expenses) { double totalExpenses = expenses.values.fold(0.0, (sum, item) => sum + item); double balance = income - totalExpenses; print("\n--- Budget Summary ---"); print("Total Income: \$${income.toStringAsFixed(2)}"); print("Total Expenses: \$${totalExpenses.toStringAsFixed(2)}"); print("Net Balance: \$${balance.toStringAsFixed(2)}"); print("\nExpense Details:"); expenses.forEach((key, value) { print("- $key: \$${value.toStringAsFixed(2)}"); }); if (balance < 0) { print("⚠ Warning: You are running a deficit!"); } else if (balance == 0) { print("⚠ Warning: No remaining balance."); } else { print("✅ Your budget is in good shape."); } }