import 'dart:io'; List> incomeList = []; List> expenseList = []; // تعريف ثابت للضريبة (Optional) const double TAX_RATE = 0.15; // 15% ضريبة [cite: 100] // دالة لحساب المجموع الكلي من قائمة (دخل أو مصروفات) double _calculateTotal(List> list) { return list.fold(0.0, (sum, item) => sum + item['amount']); } double? _getAmountInput(String prompt) { stdout.write(prompt); String? input = stdin.readLineSync(); double? amount = double.tryParse(input ?? ""); if (amount == null || amount <= 0) { print("Invalid input. Please enter a valid positive numeric amount"); return null; } return amount; } void main() { print("Welcome to the Budget Management Application!"); while (true) { print("\n\nPlease choose an option:"); print("1. Add Income"); print("2. Add Expense"); print("3. View Summary (Net Profit/Loss)"); print("4. Exit"); stdout.write("Enter your choice: "); String? choice = stdin.readLineSync(); if (choice == null || choice.isEmpty) { print("Invalid input. Please enter a number from 1 to 4."); continue; } switch (choice) { case "1": stdout.write("Enter income description: "); String? description = stdin.readLineSync(); double? amount = _getAmountInput("Enter income amount: \$"); if (description != null && description.isNotEmpty && amount != null) { incomeList.add({'description': description, 'amount': amount}); print("Income added successfully!"); } break; case "2": stdout.write("Enter expense description: "); String? description = stdin.readLineSync(); double? amount = _getAmountInput("Enter expense amount: \$"); if (description != null && description.isNotEmpty && amount != null) { expenseList.add({'description': description, 'amount': amount}); print("Expense added successfully!"); } break; case "3": double totalIncome = _calculateTotal(incomeList); double totalExpenses = _calculateTotal(expenseList); double netProfitLoss = totalIncome - totalExpenses; print("\n--- Monthly Budget Summary ---"); print("Total Income: \$${totalIncome.toStringAsFixed(2)}"); print("Total Expenses: \$${totalExpenses.toStringAsFixed(2)}"); print("------------------------------"); if (netProfitLoss > 0) { double taxAmount = 0.0; taxAmount = netProfitLoss > 0 ? netProfitLoss * TAX_RATE : 0.0; print("Net Profit: \$${netProfitLoss.toStringAsFixed(2)}"); print("Tax to be paid (15%): \$${taxAmount.toStringAsFixed(2)}"); } else if (netProfitLoss < 0) { print("Net Loss: -\$${(-netProfitLoss).toStringAsFixed(2)}"); } else { print("Net Result: \$0.00 (Break Even)"); } print("------------------------------"); break; case "4": print("Exiting the application. Goodbye!"); return; default: print("Invalid choice. Please select a number from 1 to 4"); } } }