// كود تطبيق إدارة الميزانية (Budget Management Application) import 'dart:io'; // 3. Data Storage: Use lists to store multiple income and expense entries. List> incomeList = []; List> expenseList = []; void main() { print("مرحبًا بك في تطبيق إدارة الميزانية."); // 5. Control Flow & Loops: Use a loop to keep asking the user for actions while (true) { print("\nاختر الإجراء:"); print("1. إضافة دخل"); print("2. إضافة مصروف"); print("3. عرض الملخص (صافي الربح/الخسارة)"); print("4. خروج"); stdout.write("أدخل رقم الخيار: "); String? choice = stdin.readLineSync(); if (choice == '4') { print("شكرًا لاستخدامك تطبيق إدارة الميزانية. إلى اللقاء!"); break; } // 5. Control Flow & Loops: Use if/else statements to handle menu options if (choice == '1') { addTransaction(isIncome: true); } else if (choice == '2') { addTransaction(isIncome: false); } else if (choice == '3') { viewSummary(); } else { 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(); try { double amount = double.parse(amountInput!); // 4. Input Validation: Ensure no negative amounts // 4. Use logical operators to validate inputs. if (amount <= 0) { print("المبلغ يجب أن يكون قيمة موجبة."); return; } Map transaction = { 'description': description ?? "بدون وصف", 'amount': amount, }; if (isIncome) { incomeList.add(transaction); print("تم إضافة الدخل بنجاح."); } else { expenseList.add(transaction); print("تم إضافة المصروف بنجاح."); } } catch (e) { print("إدخال غير صالح. يرجى إدخال مبلغ رقمي صحيح."); } } void viewSummary() { // 7. Arithmetic Operations: Calculate total income and total expenses double totalIncome = incomeList.fold(0.0, (sum, item) => sum + item['amount']); double totalExpenses = expenseList.fold(0.0, (sum, item) => sum + item['amount']); double netProfit = totalIncome - totalExpenses; print("\n--- ملخص الميزانية ---"); // 6. String Interpolation & Operations print("إجمالي الدخل: \$${totalIncome.toStringAsFixed(2)}"); print("إجمالي المصروفات: \$${totalExpenses.toStringAsFixed(2)}"); if (netProfit > 0) { // 6. String Interpolation & Operations print("صافي الربح: \$${netProfit.toStringAsFixed(2)}"); // 8. Exercise: Tax Calculation (Optional) // Use the ternary operator to ensure the tax is only calculated if the business is profitable. double taxRate = 0.15; double taxAmount = netProfit > 0 ? netProfit * taxRate : 0.0; print("----------------------"); print("ضريبة الدخل (15%): \$${taxAmount.toStringAsFixed(2)}"); print("الربح بعد الضريبة: \$${(netProfit - taxAmount).toStringAsFixed(2)}"); } else if (netProfit < 0) { // 6. String Interpolation & Operations print("صافي الخسارة: \$${(netProfit * -1).toStringAsFixed(2)}"); } else { print("صافي الربح/الخسارة: \$0.00 (تعادل)"); } print("----------------------"); }