import 'dart:io'; // --- السؤال الثاني: Budget Management Application --- // 2. استخدام قوائم لتخزين البيانات List> incomeList = []; List> expenseList = []; void main() { // 1. الترحيب بالمستخدم وعرض القائمة print('--- Welcome to Budget Management App ---'); while (true) { print('\nاختر خيارك:'); print('1. إضافة دخل (Add Income)'); print('2. إضافة مصروف (Add Expense)'); print('3. عرض الملخص (View Summary)'); print('4. الخروج (Exit)'); stdout.write('اختر خيارك (1-4): '); String? choice = stdin.readLineSync(); switch (choice) { case '1': addTransaction(isIncome: true); break; case '2': addTransaction(isIncome: false); break; case '3': viewSummary(); break; case '4': print('👋 شكراً لاستخدامك التطبيق. إلى اللقاء!'); return; default: print('خيار غير صالح. الرجاء إدخال رقم بين 1 و 4.'); } } } void addTransaction({required bool isIncome}) { String type = isIncome ? 'الدخل' : 'المصروف'; stdout.write('ادخل وصف $type: '); String? description = stdin.readLineSync(); stdout.write('ادخل مبلغ $type: '); String? amountInput = stdin.readLineSync(); if (description != null && description.isNotEmpty && amountInput != null) { double? amount = double.tryParse(amountInput); // 3. التأكد أن الرقم موجب if (amount != null && amount > 0) { Map transaction = { 'description': description, 'amount': amount, }; if (isIncome) { incomeList.add(transaction); } else { expenseList.add(transaction); } print('✅ تم إضافة $type بنجاح!'); } else { print('خطأ: الرجاء إدخال مبلغ صحيح وموجب.'); } } else { print('خطأ: الوصف والمبلغ مطلوبان.'); } } void viewSummary() { print('\n--- ملخص الميزانية ---'); // 4. حساب مجموع الدخل double totalIncome = incomeList.fold(0, (sum, item) => sum + item['amount']); print('\nإجمالي الدخل: \$${totalIncome.toStringAsFixed(2)}'); for (var income in incomeList) { print('- ${income['description']}: \$${income['amount'].toStringAsFixed(2)}'); } // حساب مجموع المصروفات double totalExpense = expenseList.fold(0, (sum, item) => sum + item['amount']); print('\nإجمالي المصروفات: \$${totalExpense.toStringAsFixed(2)}'); for (var expense in expenseList) { print('- ${expense['description']}: \$${expense['amount'].toStringAsFixed(2)}'); } // حساب صافي الربح/الخسارة double netResult = totalIncome - totalExpense; print('\n--------------------'); if (netResult >= 0) { print('💰 صافي الربح: \$${netResult.toStringAsFixed(2)}'); // 5. (اختياري) حساب الضريبة double tax = netResult * 0.15; print('💸 الضريبة (15%): \$${tax.toStringAsFixed(2)}'); print('📈 الربح بعد الضريبة: \$${(netResult - tax).toStringAsFixed(2)}'); } else { // استخدام abs() لعرض الخسارة كرقم موجب print('📉 صافي الخسارة: \$${netResult.abs().toStringAsFixed(2)}'); } print('--------------------'); }