import 'dart:io'; void main() { print('welcome to the smart home!'); const int minTemp = 15; const int maxTemp = 30; bool lightsOn = false; double thermostatTemp = 20.0; bool securityArmed = false; bool running = true; while (running) { print("\n---------------------"); 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? input = stdin.readLineSync(); int? choice = int.tryParse(input ?? ""); if (choice == null || choice < 1 || choice > 5) { print("invalid choice please enter a number between 1 and 5 "); continue; } switch (choice) { case 1: lightsOn = !lightsOn; String status = lightsOn ? "ON " : "OFF"; print("Lights are now $status"); break; case 2: stdout.write("set thermostat temperture ($minTemp-$maxTemp):"); String? tempInput = stdin.readLineSync(); double? newTemp = double.tryParse(tempInput ?? ""); if (newTemp == null || newTemp < minTemp || newTemp > maxTemp) { print("invalid temperture must be between $minTemp and $maxTemp"); break; } thermostatTemp = newTemp; print("thermostatTemp set to ${thermostatTemp.toStringAsFixed(1)}"); break; case 3: securityArmed = !securityArmed; String secStatus = securityArmed ? "ARMED" : "DISARMED"; print("security System is now $secStatus"); break; case 4: print("\n--- System status---"); print("Lights:${lightsOn ? "ON" : "OFF"}"); String SecurityDisplay = (securityArmed ? "armed" : "disarmed") .toUpperCase(); print("security System:$SecurityDisplay"); String tempMessage = ""; bool isMultipleOf3 = thermostatTemp % 3 == 0; bool isMultipleOf5 = thermostatTemp % 5 == 0; if (isMultipleOf3 && isMultipleOf5) { tempMessage = "Perfect Day"; } else if (isMultipleOf3) { tempMessage = "Cool Day"; } else if (isMultipleOf5) { tempMessage = "warm Day"; } print("Thermostat:${thermostatTemp.toStringAsFixed(1)}${tempMessage}"); break; case 5: running = false; print("Exiting the system goodbye!"); break; } } } import 'dart:io'; List> incomeList = []; List> expenseList = []; void main() { bool keepAppRunning = true; print('Welcome to the Budget Management Application!'); while (keepAppRunning) { displayMenu(); String? choice = stdin.readLineSync(); switch (choice) { case '1': // Call function to add income addEntry('income', incomeList); break; case '2': // Call function to add expense addEntry('expense', expenseList); break; case '3': viewSummary(); break; case '4': keepAppRunning = false; print('Exiting the application. Goodbye!'); break; default: print('Invalid choice. Please enter a number from 1 to 4.'); } print('\n----------------------------------------\n'); } } void displayMenu() { print('Please choose an action:'); print('1. Add income'); print('2. Add expense'); print('3. View summary'); print('4. Exit program'); stdout.write('Enter your choice (1-4): '); } void addEntry(String type, List> list) { // 1. Get description stdout.write('Enter $type description: '); String? description = stdin.readLineSync(); if (description == null || description.isEmpty) { description = 'No Description'; } double? amount; bool isValid = false; while (!isValid) { stdout.write('Enter $type amount (must be a non-negative number): '); String? input = stdin.readLineSync(); amount = double.tryParse(input ?? ''); if (amount != null && amount >= 0) { isValid = true; } else { print('Error: Invalid amount. Please enter a valid non-negative number.'); } } list.add({'description': description, 'amount': amount!}); print('\n${type.toUpperCase()} added successfully!'); } void viewSummary() { print('---------------BUDGET SUMMARY ---------------'); double totalIncome = incomeList.fold( 0.0, (sum, item) => sum + (item['amount'] as double), ); double totalExpenses = expenseList.fold( 0.0, (sum, item) => sum + (item['amount'] as double), ); double netProfit = totalIncome - totalExpenses; print('Totals:'); print(' * Total Income: \$${totalIncome.toStringAsFixed(2)}'); print(' * Total Expenses: \$${totalExpenses.toStringAsFixed(2)}'); print(''); if (netProfit >= 0) { print(' Net Profit: \$${netProfit.toStringAsFixed(2)}'); double taxRate = 0.15; double taxAmount = netProfit > 0 ? netProfit * taxRate : 0.0; if (taxAmount > 0) { print('Tax Due (15% of profit): \$${taxAmount.toStringAsFixed(2)}'); } } else { print('Net Loss: \$${netProfit.abs().toStringAsFixed(2)}'); } }