import 'dart:io'; // تعريف المتغيرات الأساسية bool lightsOn = false; double thermostatTemp = 20.0; bool securityArmed = false; void main() { while (true) { print("\nWelcome to the Smart Home System!"); print("Please choose an action:"); print("1. Toggle lights"); print("2. Set thermostat temperature"); print("3. Arm/disarm security system"); print("4. View system status"); print("5. Exit"); stdout.write("\nEnter your choice: "); String? choice = stdin.readLineSync(); switch (choice) { case '1': lightsOn = !lightsOn; print("Lights are now ${lightsOn ? 'ON' : 'OFF'}."); break; case '2': stdout.write("Set thermostat temperature (15°C - 30°C): "); double? temp = double.tryParse(stdin.readLineSync()!); if (temp != null && temp >= 15 && temp <= 30) { thermostatTemp = temp; print("Thermostat set to ${thermostatTemp}°C."); } else { print("Invalid temperature! Please enter a value between 15 and 30."); } break; case '3': securityArmed = !securityArmed; print("Security system is now ${securityArmed ? 'ARMED' : 'DISARMED'}."); break; case '4': print("\nSystem Status:"); print("Lights: ${lightsOn ? 'ON' : 'OFF'}"); print("Thermostat: ${thermostatTemp}°C"); print("Security System: ${securityArmed ? 'ARMED' : 'DISARMED'}"); break; case '5': print("Exiting the system. Goodbye!"); return; default: print("Invalid choice! Please enter a number from 1 to 5."); } } } السؤال الثاني import 'dart:io'; List> incomeList = []; List> expenseList = []; void main() { while (true) { print("\nWelcome to the Budget Management Application!"); print("1. Add income"); print("2. Add expense"); print("3. View summary"); print("4. Exit"); stdout.write("\nEnter your choice: "); String? choice = stdin.readLineSync(); switch (choice) { case '1': addIncome(); break; case '2': addExpense(); break; case '3': viewSummary(); break; case '4': print("Exiting the application. Goodbye!"); return; default: print("Invalid choice! Please enter a number from 1 to 4."); } } } void addIncome() { stdout.write("Enter income source: "); String source = stdin.readLineSync()!; stdout.write("Enter income amount: "); double? amount = double.tryParse(stdin.readLineSync()!); if (amount != null && amount > 0) { incomeList.add({source: amount}); print("Income added successfully."); } else { print("Invalid amount! Please enter a positive number."); } } void addExpense() { stdout.write("Enter expense category: "); String category = stdin.readLineSync()!; stdout.write("Enter expense amount: "); double? amount = double.tryParse(stdin.readLineSync()!); if (amount != null && amount > 0) { expenseList.add({category: amount}); print("Expense added successfully."); } else { print("Invalid amount! Please enter a positive number."); } } void viewSummary() { double totalIncome = incomeList.fold(0, (sum, item) => sum + item.values.first); double totalExpenses = expenseList.fold(0, (sum, item) => sum + item.values.first); double netProfit = totalIncome - totalExpenses; double tax = netProfit > 0 ? netProfit * 0.15 : 0; print("\nSummary:"); print("Total Income: \$${totalIncome.toStringAsFixed(2)}"); print("Total Expenses: \$${totalExpenses.toStringAsFixed(2)}"); print("Net Profit: \$${netProfit.toStringAsFixed(2)}"); if (netProfit > 0) { print("Tax to be paid (15%): \$${tax.toStringAsFixed(2)}"); } }