import 'dart:io'; void main() { List> incomeList = []; List> expenseList = []; bool running = true; print("=== Budget Management Application ==="); while (running) { print(""); print("Please choose an option:"); print("1. Add income"); print("2. Add expense"); print("3. View summary (net profit/loss)"); print("4. Exit"); stdout.write("Your choice: "); String? choice = stdin.readLineSync(); if (choice == '1') { addIncome(incomeList); } else if (choice == '2') { addExpense(expenseList); } else if (choice == '3') { viewSummary(incomeList, expenseList); } else if (choice == '4') { print("Exiting the application. Goodbye!"); running = false; } else { print("Invalid choice. Please try again."); } } } void addIncome(List> incomeList) { print(""); print("=== Add Income ==="); stdout.write("Enter income description: "); String? description = stdin.readLineSync(); stdout.write("Enter income amount: "); String? amountInput = stdin.readLineSync(); double? amount = double.tryParse(amountInput ?? ""); if (description == null || description.isEmpty) { print("Description cannot be empty."); return; } if (amount == null || amount <= 0) { print("Invalid amount. It must be a positive number."); return; } incomeList.add({description: amount}); print("Income added: $description - \$${amount.toStringAsFixed(2)}"); } void addExpense(List> expenseList) { print(""); print("=== Add Expense ==="); stdout.write("Enter expense description: "); String? description = stdin.readLineSync(); stdout.write("Enter expense amount: "); String? amountInput = stdin.readLineSync(); double? amount = double.tryParse(amountInput ?? ""); if (description == null || description.isEmpty) { print("Description cannot be empty."); return; } if (amount == null || amount <= 0) { print("Invalid amount. It must be a positive number."); return; } expenseList.add({description: amount}); print("Expense added: $description - \$${amount.toStringAsFixed(2)}"); } void viewSummary( List> incomeList, List> expenseList) { print(""); print("=== Budget Summary ==="); double totalIncome = 0; for (var entry in incomeList) { totalIncome += entry.values.first; } double totalExpenses = 0; for (var entry in expenseList) { totalExpenses += entry.values.first; } double net = totalIncome - totalExpenses; print("Total income: \$${totalIncome.toStringAsFixed(2)}"); print("Total expenses: \$${totalExpenses.toStringAsFixed(2)}"); if (net > 0) { print("Your net profit is \$${net.toStringAsFixed(2)}"); // Tax calculation using ternary operator (15% only if profit) double tax = net > 0 ? net * 0.15 : 0.0; print("Tax to be paid (15% of profit): \$${tax.toStringAsFixed(2)}"); } else if (net < 0) { double loss = -net; print("Your net loss is \$${loss.toStringAsFixed(2)}"); print("No tax is calculated because there is a loss."); } else { print("You are breaking even. No profit, no loss."); print("No tax is calculated."); } }