import 'dart:io' show stdout, stdin; void main() { // Lists to store income and expenses List> incomeList = []; List> expenseList = []; // Tax rate constant const double taxRate = 0.15; print('Welcome to the Budget Management Application!'); // Main program loop while (true) { print('\nPlease choose an option:'); 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(incomeList); break; case '2': addExpense(expenseList); break; case '3': viewSummary(incomeList, expenseList, taxRate); break; case '4': print('Exiting the application. Goodbye!'); return; default: print('Invalid choice! Please enter a number between 1 and 4.'); } } } void addIncome(List> incomeList) { stdout.write('Enter income description: '); String? description = stdin.readLineSync(); if (description == null || description.isEmpty) { print('Invalid description!'); return; } stdout.write('Enter income amount: '); String? amountInput = stdin.readLineSync(); try { double amount = double.parse(amountInput!); // Input validation - no negative amounts if (amount <= 0) { print('Invalid amount! Please enter a positive number.'); return; } // Add income to list incomeList.add({ 'description': description, 'amount': amount }); print('Income added successfully!'); } catch (e) { print('Invalid amount! Please enter a valid number.'); } } void addExpense(List> expenseList) { stdout.write('Enter expense description: '); String? description = stdin.readLineSync(); if (description == null || description.isEmpty) { print('Invalid description!'); return; } stdout.write('Enter expense amount: '); String? amountInput = stdin.readLineSync(); try { double amount = double.parse(amountInput!); // Input validation - no negative amounts if (amount <= 0) { print('Invalid amount! Please enter a positive number.'); return; } // Add expense to list expenseList.add({ 'description': description, 'amount': amount }); print('Expense added successfully!'); } catch (e) { print('Invalid amount! Please enter a valid number.'); } } void viewSummary(List> incomeList, List> expenseList, double taxRate) { print('\n=== BUDGET SUMMARY ==='); // Calculate totals double totalIncome = calculateTotal(incomeList); double totalExpenses = calculateTotal(expenseList); double netProfit = totalIncome - totalExpenses; // Display income details print('\nINCOME:'); if (incomeList.isEmpty) { print(' No income recorded'); } else { for (var income in incomeList) { print(' - ${income['description']}: \$${income['amount']}'); } } print(' Total income: \$${totalIncome.toStringAsFixed(2)}'); // Display expense details print('\nEXPENSES:'); if (expenseList.isEmpty) { print(' No expenses recorded'); } else { for (var expense in expenseList) { print(' - ${expense['description']}: \$${expense['amount']}'); } } print(' Total expenses: \$${totalExpenses.toStringAsFixed(2)}'); // Display net profit/loss print('\nNET RESULT:'); if (netProfit >= 0) { print(' Net profit: \$${netProfit.toStringAsFixed(2)}'); } else { print(' Net loss: \$${netProfit.abs().toStringAsFixed(2)}'); } // Tax calculation using ternary operator (only if profitable) double taxAmount = netProfit > 0 ? netProfit * taxRate : 0; if (taxAmount > 0) { print(' Tax to be paid (${(taxRate * 100).toInt()}%): \$${taxAmount.toStringAsFixed(2)}'); double profitAfterTax = netProfit - taxAmount; print(' Profit after tax: \$${profitAfterTax.toStringAsFixed(2)}'); } } double calculateTotal(List> list) { double total = 0; for (var item in list) { total += item['amount']; } return total; }