From f562e035e51e6c3a398e5c9718e7a2a87d524912 Mon Sep 17 00:00:00 2001 From: AngleAirdrop <92680828+AngleAirdrop@users.noreply.github.com> Date: Fri, 31 Oct 2025 20:24:35 +0700 Subject: [PATCH] PersonalFinanceTracker.java --- Java/PersonalFinanceTracker.java | 65 ++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 Java/PersonalFinanceTracker.java diff --git a/Java/PersonalFinanceTracker.java b/Java/PersonalFinanceTracker.java new file mode 100644 index 00000000..5d817891 --- /dev/null +++ b/Java/PersonalFinanceTracker.java @@ -0,0 +1,65 @@ +// ===================================== +// šŸ”¹ Title: Personal Finance Tracker +// ===================================== + +import java.util.*; + +class Transaction { + String type; + double amount; + String description; + + Transaction(String type, double amount, String description) { + this.type = type; + this.amount = amount; + this.description = description; + } +} + +public class FinanceTracker { + private static final List transactions = new ArrayList<>(); + private static final Scanner sc = new Scanner(System.in); + + public static void main(String[] args) { + int choice; + do { + System.out.println("\n===== PERSONAL FINANCE TRACKER ====="); + System.out.println("1. Add Income"); + System.out.println("2. Add Expense"); + System.out.println("3. View Summary"); + System.out.println("0. Exit"); + System.out.print("Choice: "); + choice = sc.nextInt(); + + switch (choice) { + case 1 -> addTransaction("Income"); + case 2 -> addTransaction("Expense"); + case 3 -> viewSummary(); + case 0 -> System.out.println("Exiting..."); + default -> System.out.println("Invalid choice!"); + } + } while (choice != 0); + } + + private static void addTransaction(String type) { + sc.nextLine(); + System.out.print("Enter amount: "); + double amount = sc.nextDouble(); + sc.nextLine(); + System.out.print("Enter description: "); + String desc = sc.nextLine(); + transactions.add(new Transaction(type, amount, desc)); + System.out.println("āœ… Transaction recorded!"); + } + + private static void viewSummary() { + double income = 0, expense = 0; + for (Transaction t : transactions) { + if (t.type.equals("Income")) income += t.amount; + else expense += t.amount; + } + System.out.println("\nšŸ’µ Income: $" + income); + System.out.println("šŸ’ø Expense: $" + expense); + System.out.println("šŸ“Š Balance: $" + (income - expense)); + } +}