// This program has been modified to be compatible with DartPad. // 'dart:io' for synchronous console input/output is not supported in DartPad. // To fix this, 'stdin.readLineSync()' has been replaced with a mock input // mechanism, and 'stdout.write()' has been replaced with 'print()'. // The program will now run through a predefined sequence of actions instead of // requiring live user interaction. // Mock input for DartPad compatibility. // This list simulates user input for demonstration purposes. List mockInput = [ "1", // Choose to Add Income "Salary", // Income description "2000", // Income amount "2", // Choose to Add Expense "Rent", // Expense description "800", // Expense amount "3", // Choose to View Summary "4", // Choose to Exit ]; int mockInputIndex = 0; String? readMockInput() { if (mockInputIndex < mockInput.length) { // Optionally print the simulated input for clarity in the console print(" (Simulated input: '${mockInput[mockInputIndex]}')"); return mockInput[mockInputIndex++]; } // If we run out of mock input, return null to simulate end of input. return null; } void main() { // Lists to store income and expenses List> incomeList = []; List> expenseList = []; print("======== Welcome to Budget Manager ========"); while (true) { print("\nMenu:"); print("1. Add Income"); print("2. Add Expense"); print("3. View Summary"); print("4. Exit"); print("Enter your choice: "); // Replaced stdout.write with print String? choice = readMockInput(); // Replaced stdin.readLineSync() // ─────────────────────────────────────────────── // 1. ADD INCOME // ─────────────────────────────────────────────── if (choice == "1") { print("Enter income description: "); // Replaced stdout.write with print String? desc = readMockInput(); // Replaced stdin.readLineSync() print("Enter income amount: "); // Replaced stdout.write with print String? amtInput = readMockInput(); // Replaced stdin.readLineSync() double? amount = double.tryParse(amtInput ?? ""); // Input validation if (amount == null || amount < 0) { print("❌ Invalid amount! Must be a positive number."); } else { incomeList.add({desc ?? "Unnamed Income": amount}); print("✅ Income added successfully."); } } // ─────────────────────────────────────────────── // 2. ADD EXPENSE // ─────────────────────────────────────────────── else if (choice == "2") { print("Enter expense description: "); // Replaced stdout.write with print String? desc = readMockInput(); // Replaced stdin.readLineSync() print("Enter expense amount: "); // Replaced stdout.write with print String? amtInput = readMockInput(); // Replaced stdin.readLineSync() double? amount = double.tryParse(amtInput ?? ""); // Input validation if (amount == null || amount < 0) { print("❌ Invalid amount! Must be a positive number."); } else { expenseList.add({desc ?? "Unnamed Expense": amount}); print("✅ Expense added successfully."); } } // ─────────────────────────────────────────────── // 3. VIEW SUMMARY // ─────────────────────────────────────────────── else if (choice == "3") { double totalIncome = 0; double totalExpenses = 0; // Calculate totals for (var item in incomeList) { totalIncome += item.values.first; } for (var item in expenseList) { totalExpenses += item.values.first; } double net = totalIncome - totalExpenses; print("\n========== Budget Summary =========="); print("Total Income: \$${totalIncome.toStringAsFixed(2)}"); print("Total Expenses: \$${totalExpenses.toStringAsFixed(2)}"); if (net > 0) { print("✅ Your net profit is \$${net.toStringAsFixed(2)}"); // Optional Tax Feature (15% of profit) double tax = net * 0.15; print("💰 Tax to be paid (15%): \$${tax.toStringAsFixed(2)}"); } else if (net < 0) { print("❌ Your net loss is \$${net.abs().toStringAsFixed(2)}"); } else { print("Your budget is balanced. No profit, no loss."); } } // ─────────────────────────────────────────────── // 4. EXIT // ─────────────────────────────────────────────── else if (choice == "4") { print("Exiting Budget Manager... Goodbye!"); return; } // ─────────────────────────────────────────────── // INVALID CHOICE // ─────────────────────────────────────────────── else { print("❌ Invalid choice. Please try again."); } } }