import 'dart:io'; void main() { // قوائم لتخزين البيانات List> incomeList = []; List> expenseList = []; bool isRunning = true; print("=== Welcome to the Budget Management Application ==="); while (isRunning) { print("\n--- Main Menu ---"); print("1. Add Income"); print("2. Add Expense"); print("3. View Summary (Profit/Loss)"); print("4. Exit"); stdout.write("Choose an option: "); String? choice = stdin.readLineSync()?.trim(); if (choice == '1') { // إضافة دخل stdout.write("Enter income description: "); String desc = stdin.readLineSync() ?? "Income"; stdout.write("Enter amount: "); double? amount = double.tryParse(stdin.readLineSync()!); if (amount != null && amount > 0) { incomeList.add({desc: amount}); print(">>> Income added successfully."); } else { print(">>> Invalid amount! Please enter a positive number."); } } else if (choice == '2') { // إضافة مصروفات stdout.write("Enter expense description: "); String desc = stdin.readLineSync() ?? "Expense"; stdout.write("Enter amount: "); double? amount = double.tryParse(stdin.readLineSync()!); if (amount != null && amount > 0) { expenseList.add({desc: amount}); print(">>> Expense added successfully."); } else { print(">>> Invalid amount! Please enter a positive number."); } } else if (choice == '3') { // حساب الإجمالي double totalIncome = 0; for (var item in incomeList) { totalIncome += item.values.first; } double totalExpense = 0; for (var item in expenseList) { totalExpense += item.values.first; } double netResult = totalIncome - totalExpense; print("\n===== Budget Summary ====="); print("Total Income: \$${totalIncome.toStringAsFixed(2)}"); print("Total Expenses: \$${totalExpense.toStringAsFixed(2)}"); if (netResult >= 0) { print("Your net profit is \$${netResult.toStringAsFixed(2)}"); // حساب الضريبة (15%) باستخدام double tax = netResult > 0 ? netResult * 0.15 : 0; if (tax > 0) { print("Tax to be paid (15%): \$${tax.toStringAsFixed(2)}"); } } else { // في حالة الخسارة (القيمة سالبة نضربها في -1 لعرضها موجبة) print("Your net loss is \$${(netResult * -1).toStringAsFixed(2)}"); } } else if (choice == '4') { print("Exiting application... Goodbye!"); isRunning = false; } else { print("Invalid option, please try again."); } } }