import 'dart:io'; void main() { bool lightsOn = false; bool securityArmed = false; int thermostat = 20; const int minTemp = 15; const int maxTemp = 30; while (true) { print('Welcome 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("Enter your choice: "); String? choice = stdin.readLineSync(); switch (choice) { case "1": // Toggle lights on/off lightsOn = !lightsOn; print('Lights are now ${lightsOn ? "ON" : "OFF"}'); break; case "2": // Set thermostat temperature stdout.write('Set thermostat temperature (15°C to 30°C): '); String? tempInput = stdin.readLineSync(); int? temp = int.tryParse(tempInput!); if (temp != null && temp > maxTemp) { print('Invalid temperature! Please enter a value between 15°C and 30°C.'); } else { thermostat = temp!; print('Thermostat is set to $thermostat°C.'); } break; case "3": // Arm or disarm the security system securityArmed = !securityArmed; print('Security System is now ${securityArmed ? "ARMED" : "DISARMED"}'); break; case "4": // View system status String tempMessage = (thermostat > 24) ? "Warm Day" : "Cool Day"; print("System Status:"); print('Lights: ${lightsOn ? "ON" : "OFF"}'); print('Thermostat: $thermostat°C'); print('Security System: ${securityArmed ? "ARMED" : "DISARMED"}'); print('Today is a $tempMessage.'); break; case "5": // Exit the program print('Exiting the Smart Home System. Goodbye!'); return; default: print('Invalid option. Please choose a valid number between 1 and 5.'); } } } // -------------------------------------------- // Below is the code from second.dart // -------------------------------------------- import 'dart:io'; void main() { List> incomeList = []; List> expenseList = []; print('Welcome to the Budget Management Application!'); while (true) { print('\nSelect an option:'); print('1. Add Income'); print('2. Add Expense'); print('3. View Net Profit/Loss'); print('4. Exit'); String? choice = stdin.readLineSync(); if (choice == '1') { addIncome(incomeList); } else if (choice == '2') { addExpense(expenseList); } else if (choice == '3') { viewNetProfitOrLoss(incomeList, expenseList); } else if (choice == '4') { print('Thank you for using the Budget Management Application!'); break; } else { print('Invalid choice, please try again.'); } } } void addIncome(List> incomeList) { print('Enter income description:'); String? description = stdin.readLineSync(); print('Enter income amount:'); double? amount = _getValidAmount(); if (description != null && amount != null) { incomeList.add({'description': amount}); print('Income added: $description - \$${amount}'); } } void addExpense(List> expenseList) { print('Enter expense description:'); String? description = stdin.readLineSync(); print('Enter expense amount:'); double? amount = _getValidAmount(); if (description != null && amount != null) { expenseList.add({'description': amount}); print('Expense added: $description - \$${amount}'); } } void viewNetProfitOrLoss(List> incomeList, List> expenseList) { double totalIncome = incomeList.fold(0, (sum, income) => sum + income.values.first); double totalExpenses = expenseList.fold(0, (sum, expense) => sum + expense.values.first); double netProfitOrLoss = totalIncome - totalExpenses; if (netProfitOrLoss > 0) { double tax = netProfitOrLoss * 0.15; print('Your net profit is \$${netProfitOrLoss}'); print('Tax to be paid: \$${tax.toStringAsFixed(2)}'); } else if (netProfitOrLoss < 0) { print('Your net loss is \$${netProfitOrLoss.abs()}'); } else { print('You broke even, no profit or loss.'); } } double? _getValidAmount() { double? amount; while (true) { try { String? input = stdin.readLineSync(); amount = double.tryParse(input ?? ''); if (amount != null && amount >= 0) { break; } else { print('Please enter a valid non-negative amount.'); } } catch (e) { print('Invalid input. Please enter a valid amount.'); } } return amount; }