import 'dart:io'; void main() { print("Welcome to the Budget Management Application!\n"); // Lists to store income and expenses List> incomeList = []; List> expenseList = []; while (true) { print("\nPlease choose an option:"); print("1. Add Income"); print("2. Add Expense"); print("3. View Summary"); print("4. Exit"); stdout.write("Enter your choice (1-4): "); String? choice = stdin.readLineSync(); if (choice == '1') { // Add income stdout.write("Enter income description: "); String? description = stdin.readLineSync(); double? amount; while (true) { stdout.write("Enter income amount: "); String? inputAmount = stdin.readLineSync(); if (inputAmount != null && double.tryParse(inputAmount) != null) { amount = double.parse(inputAmount); if (amount >= 0) { break; } else { print("Amount cannot be negative. Try again."); } } else { print("Invalid number. Please enter a valid numeric amount."); } } incomeList.add({description!: amount}); print("Income added successfully!"); } else if (choice == '2') { // Add expense stdout.write("Enter expense description: "); String? description = stdin.readLineSync(); double? amount; while (true) { stdout.write("Enter expense amount: "); String? inputAmount = stdin.readLineSync(); if (inputAmount != null && double.tryParse(inputAmount) != null) { amount = double.parse(inputAmount); if (amount >= 0) { break; } else { print("Amount cannot be negative. Try again."); } } else { print("Invalid number. Please enter a valid numeric amount."); } } expenseList.add({description!: amount}); print("Expense added successfully!"); } else if (choice == '3') { // View summary double totalIncome = 0; double totalExpenses = 0; print("\nIncome Summary:"); if (incomeList.isEmpty) { print("No income recorded."); } else { for (var income in incomeList) { income.forEach((desc, amt) { print("- $desc: \$${amt.toStringAsFixed(2)}"); totalIncome += amt; }); } } print("\nExpense Summary:"); if (expenseList.isEmpty) { print("No expenses recorded."); } else { for (var expense in expenseList) { expense.forEach((desc, amt) { print("- $desc: \$${amt.toStringAsFixed(2)}"); totalExpenses += amt; }); } } double net = totalIncome - totalExpenses; if (net >= 0) { print("\nYour net profit is \$${net.toStringAsFixed(2)}"); // Optional tax calculation: 15% if profit double tax = net * 0.15; print("Tax to be paid (15%): \$${tax.toStringAsFixed(2)}"); } else { print("\nYour net loss is \$${(-net).toStringAsFixed(2)}"); } } else if (choice == '4') { // Exit print("Exiting the program. Goodbye!"); break; } else { print("Invalid choice. Please enter a number between 1 and 4."); } } }