import 'dart:io'; void main() { // قوائم لتخزين الدخل والمصروفات List> incomeList = []; List> expenseList = []; while (true) { // عرض القائمة للمستخدم print("\nWelcome to the Budget Management Application!"); print("Please 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(); switch (choice) { case '1': addIncome(incomeList); break; case '2': addExpense(expenseList); break; case '3': viewSummary(incomeList, expenseList); break; case '4': print("Exiting the application. Goodbye!"); return; default: print("Invalid choice. Please try again."); } } } // دالة لإضافة دخل void addIncome(List> incomeList) { stdout.write("Enter income description: "); String? description = stdin.readLineSync(); stdout.write("Enter income amount: "); double? amount = double.tryParse(stdin.readLineSync() ?? ''); if (description != null && amount != null && amount > 0) { incomeList.add({description: amount}); print("Income added!"); } else { print("Invalid input. Please enter a valid amount."); } } // دالة لإضافة مصروف void addExpense(List> expenseList) { stdout.write("Enter expense description: "); String? description = stdin.readLineSync(); stdout.write("Enter expense amount: "); double? amount = double.tryParse(stdin.readLineSync() ?? ''); if (description != null && amount != null && amount > 0) { expenseList.add({description: amount}); print("Expense added!"); } else { print("Invalid input. Please enter a valid amount."); } } // دالة لحساب وعرض الملخص void viewSummary(List> incomeList, List> expenseList) { double totalIncome = incomeList.fold(0, (sum, item) => sum + item.values.first); double totalExpenses = expenseList.fold(0, (sum, item) => sum + item.values.first); double netProfit = totalIncome - totalExpenses; double tax = (netProfit > 0) ? netProfit * 0.15 : 0; print("\nSummary:"); print("Total income: \$${totalIncome.toStringAsFixed(2)}"); print("Total expenses: \$${totalExpenses.toStringAsFixed(2)}"); if (netProfit >= 0) { print("Net profit: \$${netProfit.toStringAsFixed(2)}"); print("Tax to be paid: \$${tax.toStringAsFixed(2)}"); } else { print("Net loss: \$${(-netProfit).toStringAsFixed(2)}"); } }