import 'dart:io'; \\lapr void main() { // رسالة ترحيب بالمستخدم print('Welcome to the Budget Management Application!'); // قوائم لتخزين الدخل والمصروفات List> incomeList = []; // كل دخل مخزن كخريطة: {الوصف: المبلغ} List> expenseList = []; // كل مصروف مخزن كخريطة: {الوصف: المبلغ} // حلقة التفاعل المستمر مع المستخدم while (true) { // عرض القائمة للمستخدم print('\nPlease choose an option:'); print('1. Add income'); // الخيار 1: إضافة دخل print('2. Add expense'); // الخيار 2: إضافة مصروف print('3. View summary'); // الخيار 3: عرض ملخص الميزانية print('4. Exit'); // الخيار 4: الخروج من البرنامج \\ قراءة إدخال المستخدم stdout.write('Enter your choice: '); String? choice = stdin.readLineSync(); // يمكن أن يكون null إذا لم يدخل المستخدم شيئًا // تنفيذ الخيار المختار باستخدام switch switch (choice) { case '1': // إضافة دخل جديد stdout.write('Enter income description: '); String desc = stdin.readLineSync() ?? ''; // قراءة الوصف، إذا فارغ يتم استخدام '' stdout.write('Enter income 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 non-negative number.'); // رسالة خطأ } break; case '2': // إضافة مصروف جديد stdout.write('Enter expense description: '); String desc = stdin.readLineSync() ?? ''; // قراءة الوصف stdout.write('Enter expense 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 non-negative number.'); // رسالة خطأ } break; case '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 net = totalIncome - totalExpense; // حساب صافي الربح أو الخسارة print('\n--- Summary ---'); print('Total Income: \$${totalIncome}'); // عرض إجمالي الدخل print('Total Expenses: \$${totalExpense}'); // عرض إجمالي المصروفات // التحقق من الربح أو الخسارة if (net >= 0) { print('Your net profit is \$${net}'); // الربح double tax = net * 0.15; // حساب الضريبة 15% print('Tax to pay (15%): \$${tax}'); // عرض الضريبة } else { print('Your net loss is \$${-net}'); // الخسارة } break; case '4': // الخروج من البرنامج print('Exiting... Goodbye!'); return; // إنهاء البرنامج default: // إدخال غير صحيح print('Invalid choice, please try again.'); } } }