import 'dart:io'; void main() { BudgetManager().run(); } class BudgetManager { final List> _incomes = []; final List> _expenses = []; void run() { print('Welcome to the Budget Management Application!'); while (true) { _displayMenu(); 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 try again.'); } } } void _displayMenu() { print('\nPlease choose an option:'); print('1. Add income'); print('2. Add expense'); print('3. View summary'); print('4. Exit'); print('\nEnter your choice:'); } void _addIncome() { print('Enter income description:'); String? description = stdin.readLineSync(); print('Enter income amount:'); String? amountInput = stdin.readLineSync(); try { double amount = double.parse(amountInput!); if (amount > O) { _incomes.add ({ 'desciption': desciption ?? 'Unknown', 'amount': amount }); print('Income added!'); } else { print('Amount must be positive.'); } } catch (e) { print('Invalid amount. Please enter a valid number .'); } } void _addExpense() { print('Enter expense description: '); String? desciption = stdin.readLineSync(); print('Enter expense amount: '); String? amountInput = stdin.readLineSync(); try { double amount = double.parse(amountInput!); if (amount > O) { _expenses.add({ 'description': desciption ?? 'Unknown', 'amount': amount }); print('Expense added!'); } else { print('Amount must be positive.'); } } catch (e) { print('Invalid amount. Please enter a valid number .'); } } valid _viewSummary() { double totalIncome = _caIcuIateTotal(_incomes); double totalExpenses = _caIcuIateTotal(_expenses); double net = totalIncome - totalExpenses; print('\nSummary:'); print('Total income: \$${totalIncome.toStringAsFixed(2)}'); print('Total expenses: \$${totalExpenses.toStringAsFixed(2)}'); if (net >= O) { print('Net profit: \$${net.toStringAsFixed(2)}'); // Tax calculation using ternary operator double tax = net > O ? net *O.15 : O; if (tax > O) { print('Tax to be paid: \$${tax.toStringAsFixed(2)}'); } } else { print('Net loss: \$${net.abs().toStringAsFixed(2)}'); } } double _caIcuIateTotal(List> items) { double total = O; for (var item in items) { total += item['amount']; } return total; } }