السؤال الثاني 

import java.util.Scanner;

public class BudgetManagementApp {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        double totalIncome = 0;
        double totalExpenses = 0;
        final double TAX_RATE = 0.15;   // 15% ضريبة

        int choice;

        do {
            System.out.println("\nWelcome to the Budget Management Application!");
            System.out.println("Please choose an option:");
            System.out.println("1. Add income");
            System.out.println("2. Add expense");
            System.out.println("3. View summary");
            System.out.println("4. Exit");
            System.out.print("Enter your choice: ");

            choice = input.nextInt();
            input.nextLine(); // تنظيف السطر

            switch (choice) {

                case 1:
                    System.out.print("Enter income description: ");
                    String incomeDesc = input.nextLine();

                    System.out.print("Enter income amount: ");
                    double incomeAmount = input.nextDouble();

                    totalIncome += incomeAmount;
                    System.out.println("Income added!");
                    break;

                case 2:
                    System.out.print("Enter expense description: ");
                    String expenseDesc = input.nextLine();

                    System.out.print("Enter expense amount: ");
                    double expenseAmount = input.nextDouble();

                    totalExpenses += expenseAmount;
                    System.out.println("Expense added!");
                    break;

                case 3:
                    double netProfit = totalIncome - totalExpenses;

                    // Ternary Operator لحساب الضريبة فقط إذا كان هناك ربح
                    double tax = (netProfit > 0) ? netProfit * TAX_RATE : 0;

                    System.out.println("\nSummary:");
                    System.out.println("Total income: $" + totalIncome);
                    System.out.println("Total expenses: $" + totalExpenses);

                    if (netProfit > 0) {
                        System.out.println("Net profit: $" + netProfit);
                        System.out.println("Tax to be paid: $" + tax);
                    } else if (netProfit < 0) {
                        System.out.println("Net loss: $" + Math.abs(netProfit));
                        System.out.println("No tax calculated (business in loss).");
                    } else {
                        System.out.println("Break-even (no profit, no loss).");
                        System.out.println("No tax to be paid.");
                    }
                    break;

                case 4:
                    System.out.println("Exiting the application. Goodbye!");
                    break;

                default:
                    System.out.println("Invalid choice. Please try again.");
            }

        } while (choice != 4);

        input.close();
    }
}