import 'dart:io'; void main() { List> incomes = []; List> expenses = []; while (true) { print('\nWelcome to the Budget Management Application!'); print('Please 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': // إضافة دخل stdout.write('Enter income description: '); String? incomeDesc = stdin.readLineSync(); stdout.write('Enter income amount: '); String? incomeAmountInput = stdin.readLineSync(); double? incomeAmount = double.tryParse(incomeAmountInput ?? ''); if (incomeAmount == null || incomeAmount < 0) { print('Invalid amount! Please enter a positive number.'); } else { incomes.add({incomeDesc ?? 'Unknown': incomeAmount}); print('Income added!'); } break; case '2': // إضافة مصروف stdout.write('Enter expense description: '); String? expenseDesc = stdin.readLineSync(); stdout.write('Enter expense amount: '); String? expenseAmountInput = stdin.readLineSync(); double? expenseAmount = double.tryParse(expenseAmountInput ?? ''); if (expenseAmount == null || expenseAmount < 0) { print('Invalid amount! Please enter a positive number.'); } else { expenses.add({expenseDesc ?? 'Unknown': expenseAmount}); print('Expense added!'); } break; case '3': // عرض الملخص double totalIncome = 0; double totalExpense = 0; for (var inc in incomes) { totalIncome += inc.values.first; } for (var exp in expenses) { totalExpense += exp.values.first; } double netProfit = totalIncome - totalExpense; print('\nSummary:'); print('Total income: \$${totalIncome.toStringAsFixed(2)}'); print('Total expenses: \$${totalExpense.toStringAsFixed(2)}'); if (netProfit > 0) { double tax = netProfit * 0.15; print('Net profit: \$${netProfit.toStringAsFixed(2)}'); print('Tax to be paid: \$${tax.toStringAsFixed(2)}'); } else if (netProfit < 0) { print('Net loss: \$${netProfit.abs().toStringAsFixed(2)}'); print('No tax to be paid.'); } else { print('Break-even: No profit or loss.'); } break; case '4': print('Exiting the application. Goodbye!'); return; default: print('Invalid choice! Please try again.'); } } } القوائم (Lists): • incomes لتخزين الدخل. • expenses لتخزين المصروفات. • المدخلات: المستخدم يكتب الوصف والمبلغ لكل دخل أو مصروف. • الحسابات: • totalIncome و totalExpense تجمع القيم. • netProfit = totalIncome - totalExpense • الضريبة: يتم حساب 15٪ من الربح فقط إذا كان هناك ربح (باستخدام المشغل الثلاثي ? :). import 'dart:io'; void main() { List> incomes = []; List> expenses = []; while (true) { print('\nWelcome to the Budget Management Application!'); print('Please 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': // إضافة دخل stdout.write('Enter income description: '); String? incomeDesc = stdin.readLineSync(); stdout.write('Enter income amount: '); String? incomeAmountInput = stdin.readLineSync(); double? incomeAmount = double.tryParse(incomeAmountInput ?? ''); if (incomeAmount == null || incomeAmount < 0) { print('Invalid amount! Please enter a positive number.'); } else { incomes.add({incomeDesc ?? 'Unknown': incomeAmount}); print('Income added!'); } break; case '2': // إضافة مصروف stdout.write('Enter expense description: '); String? expenseDesc = stdin.readLineSync(); stdout.write('Enter expense amount: '); String? expenseAmountInput = stdin.readLineSync(); double? expenseAmount = double.tryParse(expenseAmountInput ?? ''); if (expenseAmount == null || expenseAmount < 0) { print('Invalid amount! Please enter a positive number.'); } else { expenses.add({expenseDesc ?? 'Unknown': expenseAmount}); print('Expense added!'); } break; case '3': // عرض الملخص double totalIncome = 0; double totalExpense = 0; print('\n========== Income Details =========='); if (incomes.isEmpty) { print('No income added yet.'); } else { for (var inc in incomes) { print('- ${inc.keys.first}: \$${inc.values.first.toStringAsFixed(2)}'); totalIncome += inc.values.first; } } print('\n========== Expense Details =========='); if (expenses.isEmpty) { print('No expenses added yet.'); } else { for (var exp in expenses) { print('- ${exp.keys.first}: \$${exp.values.first.toStringAsFixed(2)}'); totalExpense += exp.values.first; } } double netProfit = totalIncome - totalExpense; print('\n========== Summary =========='); print('Total income: \$${totalIncome.toStringAsFixed(2)}'); print('Total expenses: \$${totalExpense.toStringAsFixed(2)}'); if (netProfit > 0) { double tax = netProfit * 0.15; print('Net profit: \$${netProfit.toStringAsFixed(2)}'); print('Tax to be paid: \$${tax.toStringAsFixed(2)}'); } else if (netProfit < 0) { print('Net loss: \$${netProfit.abs().toStringAsFixed(2)}'); print('No tax to be paid.'); } else { print('Break-even: No profit or loss.'); } break; case '4': print('Exiting the application. Goodbye!'); return; default: print('Invalid choice! Please try again.'); } } } الآن عند اختيار الخيار رقم 3 (View summary): سيظهر الناتج بهذا الشكل ========== Income Details ========== - Sales: $10000.00 - Investment: $2000.00 ========== Expense Details ========== - Rent: $3000.00 - Salaries: $1500.00 ========== Summary ========== Total income: $12000.00 Total expenses: $4500.00 Net profit: $7500.00 Tax to be paid: $1125.00