// Budget Management Application import 'dart:io'; class BudgetApp { List> incomeList = []; List> expenseList = []; void addIncome() { stdout.write('Enter income description: '); String? desc = stdin.readLineSync(); stdout.write('Enter income amount: '); double? amount = double.tryParse(stdin.readLineSync() ?? ''); if (amount != null && amount > 0) { incomeList.add({desc ?? 'Unknown': amount}); print('Income added successfully.'); } else { print('Invalid amount!'); } } void addExpense() { stdout.write('Enter expense description: '); String? desc = stdin.readLineSync(); stdout.write('Enter expense amount: '); double? amount = double.tryParse(stdin.readLineSync() ?? ''); if (amount != null && amount > 0) { expenseList.add({desc ?? 'Unknown': amount}); print('Expense added successfully.'); } else { print('Invalid amount!'); } } void viewSummary() { double totalIncome = incomeList.fold(0, (sum, item) => sum + item.values.first); double totalExpense = expenseList.fold(0, (sum, item) => sum + item.values.first); double netProfit = totalIncome - totalExpense; print('\n--- Budget Summary ---'); print('Total Income: \$${totalIncome.toStringAsFixed(2)}'); print('Total Expenses: \$${totalExpense.toStringAsFixed(2)}'); if (netProfit >= 0) { print('Net Profit: \$${netProfit.toStringAsFixed(2)}'); } else { print('Net Loss: \$${netProfit.abs().toStringAsFixed(2)}'); } // حساب الضريبة (اختياري) double tax = 0.15 * (netProfit > 0 ? netProfit : 0); print('Tax (15% on profit): \$${tax.toStringAsFixed(2)}'); } void run() { while (true) { print('\nWelcome to the Budget Management Application!'); print('1. Add Income'); print('2. Add Expense'); print('3. View Summary'); print('4. Exit'); stdout.write('Enter your choice: '); String? choice = stdin.readLineSync(); switch (choice) { case '1': addIncome(); break; case '2': addExpense(); break; case '3': viewSummary(); break; case '4': print('Exiting program. Goodbye!'); return; default: print('Invalid choice. Try again.'); } } } } void main() { BudgetApp app = BudgetApp(); app.run(); }