import 'dart:io'; // Tax rate as constant const double TAX_RATE = 0.15; void main() { // Data storage using Lists of Maps List> incomeList = []; List> expenseList = []; print("=" * 50); print("Welcome to the Budget Management Application!"); print("=" * 50); bool running = true; while (running) { // Display menu 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(); // Handle menu options with if/else if (choice == '1') { // Add income addTransaction(incomeList, "income"); } else if (choice == '2') { // Add expense addTransaction(expenseList, "expense"); } else if (choice == '3') { // View summary displaySummary(incomeList, expenseList); } else if (choice == '4') { // Exit running = false; print("\nExiting the application. Goodbye!"); } else { print("Invalid choice! Please enter 1-4."); } } } void addTransaction(List> transactionList, String type) { stdout.write("Enter $type description: "); String? description = stdin.readLineSync(); if (description == null || description.isEmpty) { print("Description cannot be empty!"); return; } stdout.write("Enter $type amount: "); String? amountInput = stdin.readLineSync(); if (amountInput != null) { double? amount = double.tryParse(amountInput); // Input validation - no negative amounts using logical operators if (amount != null && amount > 0) { // Add to list as Map with description and amount transactionList.add({description: amount}); print("$type added successfully!"); } else { print("Invalid amount! Please enter a positive number."); } } } void displaySummary(List> incomeList, List> expenseList) { print("\n" + "=" * 40); print("SUMMARY"); print("=" * 40); // Calculate totals using arithmetic operations double totalIncome = 0; double totalExpense = 0; print("INCOME:"); if (incomeList.isEmpty) { print(" No income entries"); } else { for (var income in incomeList) { income.forEach((description, amount) { // String interpolation for display print(" - $description: \$${amount.toStringAsFixed(2)}"); totalIncome += amount; }); } } print("\nEXPENSES:"); if (expenseList.isEmpty) { print(" No expense entries"); } else { for (var expense in expenseList) { expense.forEach((description, amount) { print(" - $description: \$${amount.toStringAsFixed(2)}"); totalExpense += amount; }); } } // Calculate net profit/loss double netAmount = totalIncome - totalExpense; print("\n" + "-" * 30); print("Total Income: \$${totalIncome.toStringAsFixed(2)}"); print("Total Expenses: \$${totalExpense.toStringAsFixed(2)}"); // Display with appropriate message using string interpolation if (netAmount >= 0) { print("Net Profit: \$${netAmount.toStringAsFixed(2)}"); // Tax calculation using ternary operator double tax = netAmount > 0 ? netAmount * TAX_RATE : 0; if (tax > 0) { print("Tax to be paid (15%): \$${tax.toStringAsFixed(2)}"); } } else { print("Net Loss: \$${netAmount.abs().toStringAsFixed(2)}"); print("No tax to be paid (business not profitable)"); } print("=" * 40); }