0% found this document useful (0 votes)
20 views16 pages

Java Expense Manager Project

The document outlines a Java mini project titled 'Expense Manager' developed for an Object Oriented Programming course. It describes the application's purpose of helping users track and manage expenses through features like expense tracking, budgeting, and financial analysis, while detailing key Java concepts utilized in the code such as classes, encapsulation, and exception handling. The project includes various classes for managing categories and expenses, a service class for user interaction, and methods for generating reports on spending patterns.

Uploaded by

kashishj405
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views16 pages

Java Expense Manager Project

The document outlines a Java mini project titled 'Expense Manager' developed for an Object Oriented Programming course. It describes the application's purpose of helping users track and manage expenses through features like expense tracking, budgeting, and financial analysis, while detailing key Java concepts utilized in the code such as classes, encapsulation, and exception handling. The project includes various classes for managing categories and expenses, a service class for user interaction, and methods for generating reports on spending patterns.

Uploaded by

kashishj405
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

JAVA MINI PROJECT

SUBJECT: Object Oriented Programming (OOP)


TITLE: Expense Manager
GROUP MEMBERS: C13 37 Diksha Manish Chhajed
C13 38 Ajinkya Chitre
C14 64 Kashish Jitendra Jain

THEORY: An expense manager site is a java prototype designed to help individuals and
businesses, track and manage their expenses. These platforms typically provide tools and
features that allow users to input, categorize, and monitor their spending invarious
categories, such as food, transportation, rent, entertainment, and more. It has been classified
as a daily, monthly and yearly tracking based on categories defined.
Common features of an expense manager site may include:
1. Expense Tracking: Users can input their daily expenses, including the amount spent, date,
and category.
2. Budgeting: Users can set budgets for different expense categories and track their progress
toward staying within those budgets.
3. Financial Analysis: These sites often offer reports and visualizations to help users
understand their spending patterns and identify areas where they can save money.

CONCEPTS: Here are some of the key Java concepts used in the code:
1. Classes and Objects:- The code defines multiple classes, each representing a different
concept within the expense management system, such as `Category`, `DateUtil`, `Expense`,
`PEMservice`, `Report`, and `Repository`. Objects of these classes are created and used to
manage data and perform operations.
2. Constructors:- The classes have constructors to initialize object properties. Constructors
are used to create instances of classes with default or custom values.
3. Encapsulation:- The classes use private fields and provide public getter and setter methods
to control access to object properties. This encapsulation ensures data integrity and security.
4. Inheritance:- Inheritance is not explicitly used in the code, but the classes follow an
object-oriented approach, and some classes, such as `Report` and `Repository`, use objects of
other classes to access their functionality.
5. Exception Handling:- The code includes try-catch blocks to handle exceptions when
parsing dates using the `SimpleDateFormat` class. It also handles potential exceptions when
working with user input.
6. User Input:- The code utilizes the `Scanner` class to interact with the user by reading input
from the console. It displays a menu and processes user choices.
7. Method Calls and Functionality:- Methods are defined in the classes to perform various
functions, such as adding categories, entering expenses, calculating totals, and generating
reports.
8. Control Flow:- The code uses control flow constructs like `while` loops and `switch`
statements to manage the flow of the application based on user input.
9. Date Handling:- The `DateUtil` class is used to parse and format dates, as well as extract
year and month information from dates. It makes use of the `SimpleDateFormat` class for
date formatting and parsing.

FEATURES: The provided code appears tis a Java program for an Expense Manager
application or site. It is designed to help users manage their expenses, record and categorize
their spending, and generate reports for monthly, yearly, and categorized expenses. Here's a
brief explanation of the code components:
1. `Category` class: This class represents expense categories. It has fields for category ID,
name, and getter and setter methods for these fields.
2. `DateUtil` class: This class contains methods to work with dates. It provides functionality
for parsing date strings, formatting dates, and extracting year and month information.
3. `Expense` class: This class represents individual expenses. It includes fields for expense
ID, category ID, amount, date, and a remark. It also has getter and setter methods for these
fields.
4. `PEMservice` class: This class serves as the main part of the application. It provides a
menu-driven interface for users to perform various operations, such as adding categories,
entering expenses, and generating expense reports. It uses the `Repository` and `Report`
classes to manage and report expenses.
5. `Report` class: This class is responsible for generating expense reports. It includes methods
for calculating monthly, yearly, and categorized expense totals, and for retrieving category
names by category ID.
6. `Repository` class: This class serves as a data repository, storing expense and category
data. It is implemented as a singleton, ensuring there is only one instance of the repository.
7. `Start` class: This class contains the `main` method and is used to start the application. It
creates an instance of `PEMservice` and initiates the menu-driven interface.
The `PEMservice` class displays a menu to the user and handles user input. Users can add
expense categories, list categories, enter expenses, list expenses, and generate various types
of expense reports, such as monthly, yearly, and categorized expenses.
The `Report` class contains methods to calculate totals based on expense data stored in the
repository.
The `Repository` class acts as a central storage for expense and category data, ensuring that
data is shared consistently throughout the application.
The `Start` class is the entry point for running the application.
Overall, the code represents a basic expense manager system that allows users to track their
expenses and generate reports to analyze their spending patterns.

CODE: public class Category{


private long categoryId=[Link]();
private String name;
public Category(String name){
[Link]=name;
}
public Category(String name,long categoryId){
[Link]=categoryId;
[Link]=name;
}
public Category(){
}
public long getCategoryId() {
return categoryId;
}
public void setCategoryId(long categoryId) {
[Link] = categoryId;
}
public String getName() {
return name;
}
public void setName(String name) {
[Link] = name;
}
}

import [Link].*;
import [Link].*;
public class DateUtil
{
public Date getDate(String dateString)
{
try
{
SimpleDateFormat df=new SimpleDateFormat("dd/MM/yyyy");
return [Link](dateString);
}
catch(Exception e)
{
[Link]("Enter valid date");
return null;
}
}
public String getString(Date date)
{
SimpleDateFormat df=new SimpleDateFormat("dd/MM/yyyy");
return [Link](date);
}
public String getYearAndMonth(Date date)
{
SimpleDateFormat df = new SimpleDateFormat("yyyy, MMMM");
return [Link](date);
}
public int getYear(Date date)
{
SimpleDateFormat df = new SimpleDateFormat("yyyy");
int year = [Link]([Link](date));
return year;
}
}
import [Link];
public class Expense {
private long expenseId = [Link]();
private long categoryId;
private float amount;
private Date date;
private String remark;
public Expense(){
}
public long getExpenseId() {
return expenseId;
}
public void setExpenseId(long expenseId) {
[Link] = expenseId;
}

public long getCategoryId() {


return categoryId;
}
public void setCategoryId(long categoryId) {
[Link] = categoryId;
}
public float getAmount() {
return amount;
}
public void setAmount(float amount) {
[Link] = amount;
}

public Date getDate() {


return date;
}
public void setDate(Date date) {
[Link] = date;
}

public String getRemark() {


return remark;
}
public void setRemark(String remark) {
[Link] = remark;
}
public Expense(long categoryId, float amount,Date date,String remark){
[Link]=categoryId;
[Link]=amount;
[Link]=date;
[Link]=remark;
}
}
import [Link].*;
public class PEMservice {
Report report=new Report();
Repository repo = [Link]();
Scanner sc = new Scanner([Link]);
private int ch;
public void showMenu(){
while(true){
printMenu();
switch(ch)
{
case 1:
addCategory();
break;
case 2:
categoryList();
break;
case 3:
expenseEntry();
break;
case 4:
expenseList();
break;
case 5:
monthlyExpenseList();
break;
case 6:
yearlyExpenseList();
break;
case 7:
categoryExpenseList();
break;
case 8:
[Link](0);
break;
default:
[Link]("Invalid Choice");
break;
}
}
}
public void printMenu(){
[Link]("\n----------MENU--------");
[Link]("[Link] Category");
[Link]("[Link] List");
[Link]("[Link] Entry");
[Link]("[Link] List");
[Link]("[Link] Expense List");
[Link]("[Link] Expense List");
[Link]("[Link] Expense List");
[Link]("[Link]");
[Link]("Enter your Choice:");
ch=[Link]();
}
public void addCategory()
{
[Link]();
[Link]("Enter Category Name:");
String catName=[Link]();
Category cat=new Category(catName);
[Link](cat);
}
public void categoryList()
{
[Link]("Category List");
List<Category> clist=[Link];
for(int i=0;i<[Link]();i++)
{
Category c=[Link](i);
[Link]((i+1)+". "+[Link]()+", " +[Link]());
}
}
public void expenseEntry()
{
categoryList();
[Link]("Select Category:");
int catChoice= [Link]();
Category selectCat=[Link](catChoice-1);
[Link]("Enter Amount:");
float amount= [Link]();
[Link]("Enter remark:");
[Link]();
String remark=[Link]();
[Link]("Enter Date in DD/MM/YYYY :");
String dateString = [Link]();
DateUtil du = new DateUtil();
Date date = [Link](dateString);
Expense exp=new Expense();
[Link]([Link]());
[Link](amount);
[Link](remark);
[Link](date);
[Link](exp);
}
public void expenseList()
{
List<Expense> expList=[Link];
for(int i=0;i<[Link]();i++)
{
Expense exp=[Link](i);
String catName=[Link]([Link]());
DateUtil du = new DateUtil();
Date date = [Link]();
String formattedDate = [Link](date);
[Link]((i + 1) + ". " +catName+", " +[Link]()+",
"+formattedDate+", "+[Link]());
}
}
public void monthlyExpenseList()
{
Map<String,Float> resultMap=[Link]();
Set<String> keys=[Link]();
float total=0.0f;
String[] keyArray = [Link](new String[[Link]()]);
for (int i = 0; i < [Link]; i++)
{
String yearMonth = keyArray[i];
total = total + [Link](yearMonth);
[Link](yearMonth + " : "+[Link](yearMonth));
}
[Link](" ------------------- ");
[Link]("Total Expense : "+total);
}
public void yearlyExpenseList()
{
Map<Integer,Float> resultMap=[Link]();
Set<Integer> years=[Link]();
float total=0.0f;
Integer[] yearArray = [Link](new Integer[[Link]()]);
for (int i = 0; i < [Link]; i++)
{
Integer year = yearArray[i];
total = total + [Link](year);
[Link](year + " : " + [Link](year));
}

[Link](" ------------------- ");


[Link]("Total Expense : "+total);
}
public void categoryExpenseList()
{
Map<String,Float> resultMap=[Link]();
Set<String> categories=[Link]();
Float total=0.0F;
String[] categoryArray = [Link](new String[[Link]()]);
for (int i = 0; i < [Link]; i++)
{
String categoryName = categoryArray[i];
total = total + [Link](categoryName);
[Link](categoryName + " : " + [Link](categoryName));
}
[Link](" ------------------- ");
[Link]("Total Expense : "+total);
}
}
import [Link].*;
public class Report {
private Repository repo = [Link]();
public Map<String, Float> calculateMonthlyTotal()
{
DateUtil du = new DateUtil();
Map<String, Float> m = new TreeMap<>();
for (int i = 0; i < [Link](); i++)
{
Expense exp = [Link](i);
Date expDate = [Link]();
String yearMonth = [Link](expDate);
if ([Link](yearMonth))
{
Float total = [Link](yearMonth);
total = total + [Link]();
[Link](yearMonth, total);
}
else
{
[Link](yearMonth, [Link]());
}
}
return m;
}
public Map<Integer, Float> calculateYearlyTotal()
{
DateUtil du = new DateUtil();
Map<Integer, Float> m = new TreeMap<>();
for (int i = 0; i < [Link](); i++)
{
Expense exp = [Link](i);
Date expDate = [Link]();
int year= [Link](expDate);
if ([Link](year))
{
Float total = [Link](year);
total = total + [Link]();
[Link](year, total);
}
else
{
[Link](year, [Link]());
}
}
return m;
}
public Map<String, Float> calculateCategoryTotal()
{
Map<String, Float> m = new TreeMap<>();
for (int i = 0; i < [Link](); i++)
{
Expense exp = [Link](i);
Long categoryId=[Link]();
String catName=[Link](categoryId);
if ([Link](catName))
{
Float total = [Link](catName);
total = total + [Link]();
[Link](catName, total);
}
else
{
[Link](catName, [Link]());
}
}
return m;
}
public String getCategoryNameById(Long categoryId)
{
for (int i = 0; i < [Link](); i++)
{
Category c = [Link](i);
if ([Link]() == categoryId)
{
return [Link]();
}
}
return null;
}
}
import [Link].*;
public class Repository{
public List<Expense> expList = new ArrayList();
public List<Category> catList = new ArrayList();
private static Repository repository;
private Repository(){
}
public static Repository getRepository(){
if(repository==null){
repository=new Repository();
}
return repository;
}
}
public class Start{
public static void main(String arg[])
{
PEMservice serve=new PEMservice();
[Link]();
}
}

OUTPUT:
Signature of the batch in charge:

Common questions

Powered by AI

The design of the "Expense Manager" utilizes object-oriented programming (OOP) principles through the creation and use of multiple classes, each representing distinct concepts within the system. The main classes include `Category`, `DateUtil`, `Expense`, `PEMservice`, `Report`, and `Repository`. Each class uses encapsulation by defining private fields and providing public getter and setter methods to control access to these fields, ensuring data integrity and security . Additionally, the use of constructors in classes such as `Category` and `Expense` allows for instance initialization with specific values . Furthermore, the `Repository` class demonstrates singleton design pattern principles by ensuring a single instance across the application, emphasizing efficient data management . The `Report` class uses method calls to compile financial analysis, which strengthens modular design and encourages code reuse .

Constructors in the Expense Manager application are used throughout to initialize objects with specific attributes. For instance, the `Category` class features constructors that allow for the creation of category instances either with a name or with both a name and a category ID. Similarly, the `Expense` class has constructors to initialize expense records either with or without detailed parameters like category ID, amount, date, and remark . These constructors are vital as they provide a structured way to instantiate objects with predefined default properties or customized settings, ensuring that objects are created with valid initial states. This practice enhances code readability and reliability by standardizing how objects are initialized across the application .

The encapsulation principle in the context of the `Expense` and `Category` classes is implemented by defining private fields for class properties, such as `categoryId`, `amount`, `date`, and `remark` in the `Expense` class, and `categoryId` and `name` in the `Category` class. Then, only allowing access to these properties through public getter and setter methods. This encapsulation ensures that direct access to the fields is restricted, supporting data integrity and security as modifications can only be made through controlled methods . This principle reduces the risk of unintentional data manipulation and enhances code maintainability by confining changes to specific parts of the codebase .

Control flow within the `PEMservice` class is managed through a combination of `while` loops, `switch` statements, and method calls to facilitate user interactions. The `showMenu` method runs an infinite `while(true)` loop that repeatedly presents a menu of options to the user, capturing their input using a `Scanner`. Based on the user's choice, determined by a `switch` statement, different methods such as `addCategory`, `expenseEntry`, and `expenseList` are invoked, each handling a specific function of the application. The control structure ensures that the user can navigate through various functionalities seamlessly and efficiently, while default cases handle invalid inputs by displaying appropriate feedback . This structured approach to control flow is essential for intuitive user navigation and maintaining application stability .

The `Report` class plays a central role in generating financial reports by incorporating comprehensive methods for calculating expense totals over specified periods and categories. It integrates with other parts of the application by accessing data stored in the `Repository` class to retrieve expense records. The methods `calculateMonthlyTotal`, `calculateYearlyTotal`, and `calculateCategoryTotal` systematically process the expenses list to provide detailed insights about spending patterns, segmented by time or category . Moreover, the `Report` class collaborates with the `DateUtil` class to extract and format relevant date components necessary for reporting. This strategic interaction allows the `Report` class to provide critical financial overviews that form the basis for user decision-making and budgeting strategies .

The `DateUtil` class plays a crucial role in the Expense Manager application by handling all date-related operations. It provides methods for parsing date strings into `Date` objects, formatting `Date` objects into strings, and extracting specific date components such as year and month information. This functionality is vital for ensuring expenses are entered with accurate date information and are processed correctly when generating reports, such as calculating monthly and yearly totals . The accuracy and usability of financial data significantly depend on precise date handling, making `DateUtil` integral for managing time-based financial data .

The singleton pattern applied in the `Repository` class effectively ensures that a single consistent instance of data storage is used throughout the Expense Manager application. This guarantees that all components of the application access the same instance of expense and category lists, thereby providing uniform data management and reducing errors related to data inconsistency . The advantage of this approach lies in its simplicity and efficiency, particularly in applications where centralized data management is crucial. However, potential drawbacks include limited scalability and increased complexity in testing, as the tight coupling around a single instance can complicate unit testing and hinder future extensions involving parallel data handling or modularization .

The Expense Manager application handles user inputs and potential errors through several mechanisms. Firstly, it employs the `Scanner` class for capturing console inputs, which are processed within a menu-driven interface provided by the `PEMservice` class. This class includes control flow statements, such as `switch` and `while` loops, to guide user interaction and manage expected actions . In terms of error handling, the application uses `try-catch` blocks, especially in the `DateUtil` class, to manage exceptions that occur during date parsing with `SimpleDateFormat`. When exceptions are caught, the application prompts the user to enter valid inputs, ensuring robust interaction and minimizing runtime errors .

The Expense Manager application supports financial analysis for users primarily through the `Report` class, which offers several functionalities: calculating monthly, yearly, and categorized expense totals. When users input expenses, the data is stored in a `Repository` class, which the `Report` class accesses to generate various financial summaries. These reports help users analyze spending patterns over time, assess their budgeting effectiveness, and identify areas for potential savings. Moreover, the categorization of expenses and visualization of financial data enable users to gain insightful analyses into their expenditure behaviors .

The `Repository` class ensures data consistency across the Expense Manager application by implementing a singleton pattern. This design choice guarantees that only one instance of the repository exists at any given time, which centralizes data management and prevents data discrepancy issues. The singleton repository holds lists of `Expense` and `Category` objects, making sure all operations performed by the application access the same data sources, thus maintaining accurate and consistent data throughout the application. Additionally, having all category and expense data stored in the repository facilitates easy retrieval and modification, which is crucial for report generation and user interactions .

You might also like