import 'dart:io'; void main() { // 1. ????? ??????? ?????? ???????? (Data Storage) List> incomeList = []; List> expenseList = []; print('--- ?????? ?? ?? ???? ????? ????????? ---'); // 2. ??????? Loop ?????? ???????? ???? (Control Flow) bool running = true; while (running) { print('\n???? ?????:'); print('1. ????? ??? (Add Income)'); print('2. ????? ????? (Add Expense)'); print('3. ??? ?????? (View Summary)'); print('4. ???? (Exit)'); stdout.write('???????: '); String? choice = stdin.readLineSync(); // 3. ??????? if-else ?????? ?? ???????? if (choice == '1') { // ????? ??? stdout.write('???? ??? ?????: '); String desc = stdin.readLineSync() ?? '???? ???'; stdout.write('???? ??????: '); double amount = double.tryParse(stdin.readLineSync() ?? '0') ?? 0; if (amount > 0) { incomeList.add({'description': desc, 'amount': amount}); print('??? ????? ????? ?????.'); } else { print('???: ???? ????? ???? ???? ???? ?? ???.'); } } else if (choice == '2') { // ????? ????? stdout.write('???? ??? ???????: '); String desc = stdin.readLineSync() ?? '???? ???'; stdout.write('???? ??????: '); double amount = double.tryParse(stdin.readLineSync() ?? '0') ?? 0; if (amount > 0) { expenseList.add({'description': desc, 'amount': amount}); print('??? ????? ??????? ?????.'); } else { print('???: ???? ????? ???? ???? ???? ?? ???.'); } } else if (choice == '3') { // 4. ???????? ???????? ???? ?????? (Arithmetic & Interpolation) double totalIncome = 0; for (var item in incomeList) { totalIncome += item['amount']; } double totalExpense = 0; for (var item in expenseList) { totalExpense += item['amount']; } double netProfit = totalIncome - totalExpense; print('\n--- ???? ????????? ---'); print('?????? ?????: $totalIncome'); print('?????? ?????????: $totalExpense'); if (netProfit >= 0) { print('???? ?????: $netProfit'); } else { print('???? ???????: ${netProfit.abs()}'); } } else if (choice == '4') { print('????? ????????? ???????. ??????!'); running = false; } else { print('?????? ??? ????? ???? ??? ????.'); } } }