import 'dart:io'; void main() { // Welcome message print("Welcome to Budget Management System"); print("------------------------------------"); // Lists to store income and expenses List> incomeList = []; List> expenseList = []; // Loop for menu while (true) { print("\nMenu:"); print("1. Add Income"); print("2. Add Expense"); print("3. View Summary"); print("4. Exit"); stdout.write("Enter your choice: "); String? choice = stdin.readLineSync(); // Add income if (choice == '1') { stdout.write("Enter income description: "); String desc = stdin.readLineSync()!; stdout.write("Enter amount: "); double? amount = double.tryParse(stdin.readLineSync()!); if (amount != null && amount > 0) { incomeList.add({desc: amount}); print("Income added successfully."); } else { print("Invalid amount!"); } } // Add expense else if (choice == '2') { stdout.write("Enter expense description: "); String desc = stdin.readLineSync()!; stdout.write("Enter amount: "); double? amount = double.tryParse(stdin.readLineSync()!); if (amount != null && amount > 0) { expenseList.add({desc: amount}); print("Expense added successfully."); } else { print("Invalid amount!"); } } // View summary else if (choice == '3') { double totalIncome = 0; double totalExpense = 0; // Calculate total income for (var item in incomeList) { totalIncome += item.values.first; } // Calculate total expenses for (var item in expenseList) { totalExpense += item.values.first; } double net = totalIncome - totalExpense; print("\n--- Budget Summary ---"); print("Total Income: \$${totalIncome}"); print("Total Expenses: \$${totalExpense}"); if (net >= 0) { print("Your net profit is \$${net}"); // Optional tax (15%) using ternary double tax = net > 0 ? net * 0.15 : 0; if (tax > 0) { print("Tax to pay (15%): \$${tax}"); } } else { print("Your net loss is \$${net.abs()}"); } } // Exit else if (choice == '4') { print("Thank you for using Budget Management System"); break; } else { print("Invalid choice, try again."); } } }