// -------- SMART HOME APP -------- import 'dart:io'; const int minTemp = 15; const int maxTemp = 30; void main() { bool lightsOn = false; int thermostat = 20; bool securityArmed = false; while (true) { print('\n=== SMART HOME ==='); print('1) تحكم بالأجهزة'); print('2) عرض الحالة'); print('3) تشغيل تطبيق الميزانية'); print('4) خروج'); stdout.write('اختيارك: '); String choice = (stdin.readLineSync() ?? '').trim(); if (choice == '1') { stdout.write('اختر الجهاز (lights / thermostat / security): '); String device = (stdin.readLineSync() ?? '').trim().toLowerCase(); switch (device) { case 'lights': stdout.write('اكتب on أو off: '); String cmd = (stdin.readLineSync() ?? '').trim().toLowerCase(); if (cmd == 'on') { lightsOn = true; print('تم تشغيل الأضواء.'); } else if (cmd == 'off') { lightsOn = false; print('تم إطفاء الأضواء.'); } else { print('أمر غير صالح.'); } break; case 'thermostat': stdout.write('أدخل درجة الحرارة ($minTemp-$maxTemp): '); String t = (stdin.readLineSync() ?? '').trim(); int? value = int.tryParse(t); if (value == null) { print('قيمة غير رقمية.'); } else if (value < minTemp || value > maxTemp) { print('خارج النطاق المسموح.'); } else { thermostat = value; print('تم ضبط الحرارة على $thermostat°C.'); } break; case 'security': stdout.write('اكتب arm أو disarm: '); String cmd = (stdin.readLineSync() ?? '').trim().toLowerCase(); if (cmd == 'arm' && !securityArmed) { securityArmed = true; print('تم تفعيل نظام الأمان.'); } else if (cmd == 'disarm' && securityArmed) { securityArmed = false; print('تم إلغاء تفعيل نظام الأمان.'); } else { print('لا تغيير أو أمر غير صالح.'); } break; default: print('جهاز غير معروف.'); } } else if (choice == '2') { String lightsStatus = lightsOn ? 'ON' : 'OFF'; String securityStatus = (securityArmed ? 'ARMED' : 'DISARMED').toUpperCase(); String dayMsg = ''; bool m3 = thermostat % 3 == 0; bool m5 = thermostat % 5 == 0; if (m3 && m5) { dayMsg = 'Perfect Day'; } else if (m3) { dayMsg = 'Cool Day'; } else if (m5) { dayMsg = 'Warm Day'; } print('\n--- SYSTEM STATUS ---'); print('Lights: $lightsStatus'); print('Thermostat: $thermostat°C ${dayMsg.isEmpty ? "" : "($dayMsg)"}'); print('Security: $securityStatus'); } else if (choice == '3') { main2(); // لتشغيل التطبيق الثاني من نفس الملف } else if (choice == '4') { print('إلى اللقاء'); break; } else { print('خيار غير صالح.'); } } } // -------- BUDGET APP -------- void main2() { List> incomeList = []; List> expenseList = []; print('مرحبًا بك في Budget Manager!'); while (true) { print('\n=== القائمة الرئيسية ==='); print('1) إضافة دخل'); print('2) إضافة مصروف'); print('3) عرض الملخص'); print('4) عودة إلى التطبيق الرئيسي'); stdout.write('اختيارك: '); String choice = (stdin.readLineSync() ?? '').trim(); if (choice == '1') { stdout.write('وصف الدخل: '); String desc = (stdin.readLineSync() ?? '').trim(); while (desc.isEmpty) { stdout.write('الوصف لا يكون فارغ: '); desc = (stdin.readLineSync() ?? '').trim(); } stdout.write('قيمة الدخل (>= 0): '); double? amount = double.tryParse((stdin.readLineSync() ?? '').trim()); while (amount == null || amount.isNaN || amount < 0) { stdout.write('قيمة غير صالحة، أدخل رقم >= 0: '); amount = double.tryParse((stdin.readLineSync() ?? '').trim()); } incomeList.add({desc: amount}); print('تم الإضافة.'); } else if (choice == '2') { stdout.write('وصف المصروف: '); String desc = (stdin.readLineSync() ?? '').trim(); while (desc.isEmpty) { stdout.write('الوصف لا يكون فارغ: '); desc = (stdin.readLineSync() ?? '').trim(); } stdout.write('قيمة المصروف (>= 0): '); double? amount = double.tryParse((stdin.readLineSync() ?? '').trim()); while (amount == null || amount.isNaN || amount < 0) { stdout.write('قيمة غير صالحة، أدخل رقم >= 0: '); amount = double.tryParse((stdin.readLineSync() ?? '').trim()); } expenseList.add({desc: amount}); print('تم الإضافة.'); } else if (choice == '3') { double totalIncome = _sum(incomeList); double totalExpense = _sum(expenseList); double net = totalIncome - totalExpense; print('\n--- الملخص ---'); print('إجمالي الدخل: $totalIncome'); print('إجمالي المصروفات: $totalExpense'); if (net > 0) { print('Your net profit is \$${net.toStringAsFixed(2)}'); double tax = net > 0 ? net * 0.15 : 0.0; if (tax > 0) { print('ضريبة 15%: \$${tax.toStringAsFixed(2)}'); print('صافي الربح بعد الضريبة: \$${(net - tax).toStringAsFixed(2)}'); } } else if (net < 0) { print('Your net loss is \$${net.abs().toStringAsFixed(2)}'); } else { print('لا ربح ولا خسارة.'); } } else if (choice == '4') { break; // يرجع لتطبيق السمارت } else { print('خيار غير صالح.'); } } } double _sum(List> list) { double s = 0; for (var m in list) { s += m.values.first; } return s; } // -------- BUDGET MANAGEMENT APP -------- import 'dart:io'; void main() { List> incomeList = []; List> expenseList = []; print('مرحبًا بك في Budget Manager!'); while (true) { print('\n=== القائمة الرئيسية ==='); print('1) إضافة دخل'); print('2) إضافة مصروف'); print('3) عرض الملخص'); print('4) خروج'); stdout.write('اختيارك: '); String choice = (stdin.readLineSync() ?? '').trim(); if (choice == '1') { stdout.write('وصف الدخل: '); String desc = (stdin.readLineSync() ?? '').trim(); while (desc.isEmpty) { stdout.write('الوصف لا يكون فارغ: '); desc = (stdin.readLineSync() ?? '').trim(); } stdout.write('قيمة الدخل (>= 0): '); double? amount = double.tryParse((stdin.readLineSync() ?? '').trim()); while (amount == null || amount.isNaN || amount < 0) { stdout.write('قيمة غير صالحة، أدخل رقم >= 0: '); amount = double.tryParse((stdin.readLineSync() ?? '').trim()); } incomeList.add({desc: amount}); print('تم الإضافة.'); } else if (choice == '2') { stdout.write('وصف المصروف: '); String desc = (stdin.readLineSync() ?? '').trim(); while (desc.isEmpty) { stdout.write('الوصف لا يكون فارغ: '); desc = (stdin.readLineSync() ?? '').trim(); } stdout.write('قيمة المصروف (>= 0): '); double? amount = double.tryParse((stdin.readLineSync() ?? '').trim()); while (amount == null || amount.isNaN || amount < 0) { stdout.write('قيمة غير صالحة، أدخل رقم >= 0: '); amount = double.tryParse((stdin.readLineSync() ?? '').trim()); } expenseList.add({desc: amount}); print('تم الإضافة.'); } else if (choice == '3') { double totalIncome = _sum(incomeList); double totalExpense = _sum(expenseList); double net = totalIncome - totalExpense; print('\n--- الملخص ---'); print('إجمالي الدخل: $totalIncome'); print('إجمالي المصروفات: $totalExpense'); if (net > 0) { print('Your net profit is \$${net.toStringAsFixed(2)}'); double tax = net > 0 ? net * 0.15 : 0.0; // ضريبة 15% (اختياري) if (tax > 0) { print('ضريبة 15%: \$${tax.toStringAsFixed(2)}'); print('صافي الربح بعد الضريبة: \$${(net - tax).toStringAsFixed(2)}'); } } else if (net < 0) { print('Your net loss is \$${net.abs().toStringAsFixed(2)}'); } else { print('لا ربح ولا خسارة.'); } // (اختياري) عرض التفاصيل if (incomeList.isEmpty) { print('\nتفاصيل الدخل: لا يوجد'); } else { print('\nتفاصيل الدخل:'); for (var m in incomeList) { print('- ${m.keys.first}: \$${m.values.first.toStringAsFixed(2)}'); } } if (expenseList.isEmpty) { print('\nتفاصيل المصروفات: لا يوجد'); } else { print('\nتفاصيل المصروفات:'); for (var m in expenseList) { print('- ${m.keys.first}: \$${m.values.first.toStringAsFixed(2)}'); } } } else if (choice == '4') { print('إلى اللقاء'); break; } else { print('خيار غير صالح.'); } } } double _sum(List> list) { double s = 0; for (var m in list) { s += m.values.first; } return s; }