Java Mini Project 2-Edited
Java Mini Project 2-Edited
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.
import java.text.*;
import java.util.*;
public class DateUtil
{
public Date getDate(String dateString)
{
try
{
SimpleDateFormat df=new SimpleDateFormat("dd/MM/yyyy");
return df.parse(dateString);
}
catch(Exception e)
{
System.out.println("Enter valid date");
return null;
}
}
public String getString(Date date)
{
SimpleDateFormat df=new SimpleDateFormat("dd/MM/yyyy");
return df.format(date);
}
public String getYearAndMonth(Date date)
{
SimpleDateFormat df = new SimpleDateFormat("yyyy, MMMM");
return df.format(date);
}
public int getYear(Date date)
{
SimpleDateFormat df = new SimpleDateFormat("yyyy");
int year = Integer.parseInt(df.format(date));
return year;
}
}
import java.util.Date;
public class Expense {
private long expenseId = System.currentTimeMillis();
private long categoryId;
private float amount;
private Date date;
private String remark;
public Expense(){
}
public long getExpenseId() {
return expenseId;
}
public void setExpenseId(long expenseId) {
this.expenseId = expenseId;
}
OUTPUT:
Signature of the batch in charge: