import 'dart:io'; class BudgetManagementApp { List> incomeList = []; List> expenseList = []; static const double taxRate = 0.15; void addIncome() { stdout.write('Enter income description: '); String? description = stdin.readLineSync(); stdout.write('Enter income amount: '); String? amountInput = stdin.readLineSync(); try { double amount = double.parse(amountInput!); if (amount < 0) { print('Invalid amount! Please enter a positive value.'); return; } incomeList.add({ 'description': description ?? 'Unknown', 'amount': amount }); print('Income added!'); } catch (e) { print('Invalid amount! Please enter a valid number.'); } } void addExpense() { stdout.write('Enter expense description: '); String? description = stdin.readLineSync(); stdout.write('Enter expense amount: '); String? amountInput = stdin.readLineSync(); try { double amount = double.parse(amountInput!); if (amount < 0) { print('Invalid amount! Please enter a positive value.'); return; } expenseList.add({ 'description': description ?? 'Unknown', 'amount': amount }); print('Expense added!'); } catch (e) { print('Invalid amount! Please enter a valid number.'); } } void viewSummary() { double totalIncome = calculateTotal(incomeList); double totalExpenses = calculateTotal(expenseList); double netProfit = totalIncome - totalExpenses; print('\nSummary:'); print('Total income: \$${totalIncome.toStringAsFixed(2)}'); print('Total expenses: \$${totalExpenses.toStringAsFixed(2)}'); if (netProfit >= 0) { print('Net profit: \$${netProfit.toStringAsFixed(2)}'); // حساب الضريبة باستخدام العامل الثلاثي double tax = netProfit > 0 ? netProfit * taxRate : 0; if (tax > 0) { print('Tax to be paid: \$${tax.toStringAsFixed(2)}'); } } else { print('Net loss: \$${(-netProfit).toStringAsFixed(2)}'); } // عرض التفاصيل if (incomeList.isNotEmpty) { print('\nIncome Details:'); for (var income in incomeList) { print('- ${income['description']}: \$${income['amount'].toStringAsFixed(2)}'); } } if (expenseList.isNotEmpty) { print('\nExpense Details:'); for (var expense in expenseList) { print('- ${expense['description']}: \$${expense['amount'].toStringAsFixed(2)}'); } } } double calculateTotal(List> list) { double total = 0; for (var item in list) { total += item['amount']; } return total; } void run() { print('Welcome to the Budget Management Application!'); 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(); break; case '2': addExpense(); break; case '3': viewSummary(); break; case '4': print('Exiting the application. Goodbye!'); return; default: print('Invalid choice! Please enter a number between 1 and 4.'); } } } } void main() { BudgetManagementApp budgetApp = BudgetManagementApp(); budgetApp.run(); }