import 'dart:io'; void main() { List> incomeList = []; List> expenseList = []; print("Welcome to the Budget Management Application!"); 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: "); String? choice = stdin.readLineSync(); if (choice == "1") { stdout.write("Enter income description: "); String? description = stdin.readLineSync(); stdout.write("Enter income amount: "); double? amount = double.tryParse(stdin.readLineSync() ?? ""); if (description != null && description.isNotEmpty && amount != null && amount > 0) { incomeList.add({"description": description, "amount": amount}); print("Income added!"); } else { print("Invalid input! Description cannot be empty and amount must be a positive number."); } } else if (choice == "2") { stdout.write("Enter expense description: "); String? description = stdin.readLineSync(); stdout.write("Enter expense amount: "); double? amount = double.tryParse(stdin.readLineSync() ?? ""); if (description != null && description.isNotEmpty && amount != null && amount > 0) { expenseList.add({"description": description, "amount": amount}); print("Expense added!"); } else { print("Invalid input! Description cannot be empty and amount must be a positive number."); } } else if (choice == "3") { double totalIncome = 0; for (var item in incomeList) { totalIncome += item["amount"]; } double totalExpenses = 0; for (var item in expenseList) { totalExpenses += item["amount"]; } double netResult = totalIncome - totalExpenses; bool isProfit = netResult > 0; print("\nSummary:"); print("Total income: \$${totalIncome.toStringAsFixed(0)}"); print("Total expenses: \$${totalExpenses.toStringAsFixed(0)}"); if (isProfit) { print("Net profit: \$${netResult.toStringAsFixed(0)}"); } else if (netResult < 0) { print("Net loss: \$${(-netResult).toStringAsFixed(0)}"); } else { print("Net result: \$0 (Break even)"); } // Tax calculation using ternary operator - only if profitable double tax = isProfit ? netResult * 0.15 : 0; if (isProfit) { print("Tax to be paid: \$${tax.toStringAsFixed(0)}"); } } else if (choice == "4") { print("Exiting the application. Goodbye!"); return; } else { print("Invalid choice. Please try again."); } } }