Budget Tracker using Java With Source Code

Introduction :

The above code is a sample implementation of a budget tracker in Java. The BudgetTracker class keeps track of a user’s expenses and incomes, and calculates the current budget balance.

The class has a constructor BudgetTracker(), which initializes two ArrayList objects, one for expenses and one for incomes, as well as a double variable balance which is set to zero.

The class has three methods:

  • addExpense(double expense): This method takes in a double value as an argument, representing an expense, and adds it to the expenses ArrayList. It also subtracts the expense from the balance.
  • addIncome(double income): This method takes in a double value as an argument, representing an income, and adds it to the incomes ArrayList. It also adds the income to the balance.
  • getBalance() : This method returns the current balance
  • printExpenses() : This method prints out all the expenses stored in the expenses ArrayList
  • printIncomes() : This method prints out all the incomes stored in the incomes ArrayList

It’s worth noting that this is just a basic example, and you might want to add more features such as handling categories, displaying the balance in a specific currency,

Source Code

Get Discount on Top Educational Courses

Brand NameDiscount InformationCoupon Codes Link
Educative.io20% discount on Educative courses and plans
W3Schools20% discount on W3Schools courses
KodeKloud10% discount on KodeKloud courses and plans
GeeksforGeeks30% discount on GeeksforGeeks courses
Target Test Prep20% discount on Target Test Prep
Coding Ninjas₹5000 discount on Coding Ninjas courses
Skillshare40% discount on Skillshare
DataCamp50% discount on DataCamp
365 Data Science57% discount on 365 Data Science Plans
Get SmarterFlat 20% discount on Get Smarter courses
SmartKeedaFlat 40% discount on SmartKeeda courses
StackSocial20% discount on StackSocial courses
				
					import java.util.ArrayList;

public class BudgetTracker {
    private ArrayList<Double> expenses;
    private ArrayList<Double> incomes;
    private double balance;

    public BudgetTracker() {
        expenses = new ArrayList<Double>();
        incomes = new ArrayList<Double>();
        balance = 0;
    }

    public void addExpense(double expense) {
        expenses.add(expense);
        balance -= expense;
    }

    public void addIncome(double income) {
        incomes.add(income);
        balance += income;
    }

    public double getBalance() {
        return balance;
    }

    public void printExpenses() {
        System.out.println("Expenses: ");
        for (double expense : expenses) {
            System.out.println(expense);
        }
    }

    public void printIncomes() {
        System.out.println("Incomes: ");
        for (double income : incomes) {
            System.out.println(income);
        }
    }
}
				
			

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

Output

Data Types in python

Find More Projects

URL Shortener Using Python Django Introduction: Long URLs can be shortened into short, shareable links with the help of the URL Shortener …

User Authentication System Using Python Django Introduction: The implementation of safe and adaptable user authentication in Django is the main goal of …

The E-Learning System using Java with a Graphical User Interface (GUI) Introduction The E-Learning System is developed using Java (with a Graphical …

Weather App Using Python Django Introduction: When a user enters the name of a city, the Weather App retrieves current weather information. …

Quiz App Using Python Django Introduction: Users can take quizzes in a variety of subjects, see their results, and monitor their progress …

resume screener in python using python introduction The hiring process often begins with reviewing numerous resumes to filter out the most suitable …

Get Huge Discounts
More java Pojects