0% found this document useful (0 votes)
11 views

Java Mini Project 2-Edited

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)
11 views

Java Mini Project 2-Edited

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
You are on page 1/ 16

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=System.currentTimeMillis();
private String name;
public Category(String name){
this.name=name;
}
public Category(String name,long categoryId){
this.categoryId=categoryId;
this.name=name;
}
public Category(){
}
public long getCategoryId() {
return categoryId;
}
public void setCategoryId(long categoryId) {
this.categoryId = categoryId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

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;
}

public long getCategoryId() {


return categoryId;
}
public void setCategoryId(long categoryId) {
this.categoryId = categoryId;
}
public float getAmount() {
return amount;
}
public void setAmount(float amount) {
this.amount = amount;
}

public Date getDate() {


return date;
}
public void setDate(Date date) {
this.date = date;
}

public String getRemark() {


return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
public Expense(long categoryId, float amount,Date date,String remark){
this.categoryId=categoryId;
this.amount=amount;
this.date=date;
this.remark=remark;
}
}
import java.util.*;
public class PEMservice {
Report report=new Report();
Repository repo = Repository.getRepository();
Scanner sc = new Scanner(System.in);
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:
System.exit(0);
break;
default:
System.out.println("Invalid Choice");
break;
}
}
}
public void printMenu(){
System.out.println("\n----------MENU--------");
System.out.println("1.Add Category");
System.out.println("2.Category List");
System.out.println("3.Expense Entry");
System.out.println("4.Expense List");
System.out.println("5.Monthly Expense List");
System.out.println("6.Yearly Expense List");
System.out.println("7.Categorized Expense List");
System.out.println("8.Exit");
System.out.print("Enter your Choice:");
ch=sc.nextInt();
}
public void addCategory()
{
sc.nextLine();
System.out.println("Enter Category Name:");
String catName=sc.nextLine();
Category cat=new Category(catName);
repo.catList.add(cat);
}
public void categoryList()
{
System.out.println("Category List");
List<Category> clist=repo.catList;
for(int i=0;i<clist.size();i++)
{
Category c=clist.get(i);
System.out.println((i+1)+". "+c.getName()+", " +c.getCategoryId());
}
}
public void expenseEntry()
{
categoryList();
System.out.println("Select Category:");
int catChoice= sc.nextInt();
Category selectCat=repo.catList.get(catChoice-1);
System.out.println("Enter Amount:");
float amount= sc.nextFloat();
System.out.println("Enter remark:");
sc.nextLine();
String remark=sc.nextLine();
System.out.println("Enter Date in DD/MM/YYYY :");
String dateString = sc.nextLine();
DateUtil du = new DateUtil();
Date date = du.getDate(dateString);
Expense exp=new Expense();
exp.setCategoryId(selectCat.getCategoryId());
exp.setAmount(amount);
exp.setRemark(remark);
exp.setDate(date);
repo.expList.add(exp);
}
public void expenseList()
{
List<Expense> expList=repo.expList;
for(int i=0;i<expList.size();i++)
{
Expense exp=expList.get(i);
String catName=report.getCategoryNameById(exp.getCategoryId());
DateUtil du = new DateUtil();
Date date = exp.getDate();
String formattedDate = du.getString(date);
System.out.println((i + 1) + ". " +catName+", " +exp.getAmount()+",
"+formattedDate+", "+exp.getRemark());
}
}
public void monthlyExpenseList()
{
Map<String,Float> resultMap=report.calculateMonthlyTotal();
Set<String> keys=resultMap.keySet();
float total=0.0f;
String[] keyArray = keys.toArray(new String[keys.size()]);
for (int i = 0; i < keyArray.length; i++)
{
String yearMonth = keyArray[i];
total = total + resultMap.get(yearMonth);
System.out.println(yearMonth + " : "+resultMap.get(yearMonth));
}
System.out.println(" ------------------- ");
System.out.println("Total Expense : "+total);
}
public void yearlyExpenseList()
{
Map<Integer,Float> resultMap=report.calculateYearlyTotal();
Set<Integer> years=resultMap.keySet();
float total=0.0f;
Integer[] yearArray = years.toArray(new Integer[years.size()]);
for (int i = 0; i < yearArray.length; i++)
{
Integer year = yearArray[i];
total = total + resultMap.get(year);
System.out.println(year + " : " + resultMap.get(year));
}

System.out.println(" ------------------- ");


System.out.println("Total Expense : "+total);
}
public void categoryExpenseList()
{
Map<String,Float> resultMap=report.calculateCategoryTotal();
Set<String> categories=resultMap.keySet();
Float total=0.0F;
String[] categoryArray = categories.toArray(new String[categories.size()]);
for (int i = 0; i < categoryArray.length; i++)
{
String categoryName = categoryArray[i];
total = total + resultMap.get(categoryName);
System.out.println(categoryName + " : " + resultMap.get(categoryName));
}
System.out.println(" ------------------- ");
System.out.println("Total Expense : "+total);
}
}
import java.util.*;
public class Report {
private Repository repo = Repository.getRepository();
public Map<String, Float> calculateMonthlyTotal()
{
DateUtil du = new DateUtil();
Map<String, Float> m = new TreeMap<>();
for (int i = 0; i < repo.expList.size(); i++)
{
Expense exp = repo.expList.get(i);
Date expDate = exp.getDate();
String yearMonth = du.getYearAndMonth(expDate);
if (m.containsKey(yearMonth))
{
Float total = m.get(yearMonth);
total = total + exp.getAmount();
m.put(yearMonth, total);
}
else
{
m.put(yearMonth, exp.getAmount());
}
}
return m;
}
public Map<Integer, Float> calculateYearlyTotal()
{
DateUtil du = new DateUtil();
Map<Integer, Float> m = new TreeMap<>();
for (int i = 0; i < repo.expList.size(); i++)
{
Expense exp = repo.expList.get(i);
Date expDate = exp.getDate();
int year= du.getYear(expDate);
if (m.containsKey(year))
{
Float total = m.get(year);
total = total + exp.getAmount();
m.put(year, total);
}
else
{
m.put(year, exp.getAmount());
}
}
return m;
}
public Map<String, Float> calculateCategoryTotal()
{
Map<String, Float> m = new TreeMap<>();
for (int i = 0; i < repo.expList.size(); i++)
{
Expense exp = repo.expList.get(i);
Long categoryId=exp.getCategoryId();
String catName=this.getCategoryNameById(categoryId);
if (m.containsKey(catName))
{
Float total = m.get(catName);
total = total + exp.getAmount();
m.put(catName, total);
}
else
{
m.put(catName, exp.getAmount());
}
}
return m;
}
public String getCategoryNameById(Long categoryId)
{
for (int i = 0; i < repo.catList.size(); i++)
{
Category c = repo.catList.get(i);
if (c.getCategoryId() == categoryId)
{
return c.getName();
}
}
return null;
}
}
import java.util.*;
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();
serve.showMenu();
}
}

OUTPUT:
Signature of the batch in charge:

You might also like