import 'dart:io'; // لاستقبال مدخلات المستخدم // 3. Data Storage: استخدام List لتخزين الإيرادات والمصروفات[cite: 82, 83, 84]. List> incomeList = []; List> expenseList = []; void main() { // 1. Main Method: يبدأ البرنامج ويعرض القائمة[cite: 68, 69]. print("========================================="); print("💰 Welcome to the Budget Management Application! 💰"); print("========================================="); // 5. Control Flow & Loops: استخدام حلقة للسماح بالتفاعل المستمر حتى الخروج[cite: 91, 92]. bool running = true; while (running) { displayMenu(); String? choice = stdin.readLineSync(); // 5. Control Flow & Loops: استخدام if/else للتعامل مع خيارات القائمة[cite: 90]. if (choice == '1') { addTransaction("Income"); // إضافة إيراد [cite: 77] } else if (choice == '2') { addTransaction("Expense"); // إضافة مصروف [cite: 78] } else if (choice == '3') { viewSummary(); // عرض الملخص [cite: 79] } else if (choice == '4') { running = false; // الخروج [cite: 81] print("Exiting the application. Goodbye!"); print("========================================="); } else { print("⚠️ Invalid choice. Please enter a number between 1 and 4."); } print("-----------------------------------------"); } } void displayMenu() { print("\nPlease choose an option:"); print("1. Add income"); print("2. Add expense"); print("3. View summary"); print("4. Exit"); stdout.write("Enter your choice: "); } void addTransaction(String type) { stdout.write("Enter $type description: "); String? description = stdin.readLineSync(); double? amount; while (amount == null || amount <= 0) { stdout.write("Enter $type amount: "); String? amountInput = stdin.readLineSync(); // 4. Input Validation: التحقق من أن القيمة عددية وموجبة (لا يوجد قيم سالبة)[cite: 86, 87]. amount = double.tryParse(amountInput ?? ""); // 4. Input Validation: استخدام المعاملات المنطقية للتحقق[cite: 88]. if (amount == null || amount <= 0) { print("❌ Invalid amount. Please enter a positive number."); } } // تخزين البيانات في القائمة المناسبة Map entry = { "description": description ?? "N/A", "amount": amount, }; if (type == "Income") { incomeList.add(entry); print("Income added!"); } else { expenseList.add(entry); print("Expense added!"); } } void viewSummary() { // 7. Arithmetic Operations: حساب الإجمالي وصافي الربح/الخسارة[cite: 97]. 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--- Summary ---"); // 6. String Interpolation: عرض الملخص باستخدام استيفاء السلاسل[cite: 94, 95]. print("Total income: \$${totalIncome.toStringAsFixed(2)}"); print("Total expenses: \$${totalExpenses.toStringAsFixed(2)}"); if (netProfit >= 0) { print("Net profit: \$${netProfit.toStringAsFixed(2)}"); // 8. Exercise: Tax Calculation (Optional): حساب الضريبة[cite: 98, 99]. double taxRate = 0.15; // 15% // 8. Exercise: استخدام المعامل الثلاثي للتأكد من حساب الضريبة فقط عند وجود ربح[cite: 101, 102]. double taxToBePaid = netProfit > 0 ? (netProfit * taxRate) : 0.0; if (taxToBePaid > 0) { print("Tax to be paid: \$${taxToBePaid.toStringAsFixed(2)} (15% of profit)"); // عرض الضريبة [cite: 103] } } else { // صافي الخسارة (القيمة السالبة) double netLoss = netProfit.abs(); print("Net loss: \$${netLoss.toStringAsFixed(2)}"); } }Bush dart budget_app.dart 1 Salary 5000