Expense Management Project Details
Expense Management Project Details
Java:
1. Packages and Classes:
a. Packages: You've organized your project into packages (com.example.project11.Model, com.example.project11.Security,
com.example.project11.Service, com.example.project11.Util) to group related classes together and avoid naming conflicts.
b. Classes: Each class represents a blueprint for objects. For example, Expense, RecurringExpense, RegularExpense, Login,
Register, Security, User, ExpenseManager, ExpenseService, and Main.
b. Polymorphism: It allows objects of different classes to be treated as objects of a common superclass (Expense), enabling
flexibility and extensibility in your code.
3. Encapsulation:
a. Private Fields and Public Methods: By making fields (date, category, amount, description, numOccurrences, frequency,
username, password, expenses, users) private and providing public methods (getters and setters), you encapsulate the internal state
of objects and control access to them.
b. Methods: Methods represent behavior associated with objects. You've defined methods like getters, authenticate, addExpense,
deleteExpense, registerUser, authenticateUser, loginUser, etc.
5. Composition:
a. Composition: It's a design technique in OOP where a class contains an instance of another class. For example, classes like
Login, Register, and ExpenseService include instances of ExpenseManager to delegate tasks related to user management and
expense handling.
6. Control Flow:
a. Decision Making: You've used if-else statements in methods like authenticateUser in Security class to authenticate users based
on their credentials.
b. Looping Constructs: The while loop in Main class is used for continuous interaction with the user until the program is exited.
Also, for-each loop is used to iterate over expenses in methods like calculateTotalExpenses in ExpenseService.
2. Inheritance:
a. Inheritance: It allows you to create new classes that are based on existing classes, inheriting their attributes and behaviors.
Subclasses like RecurringExpense and RegularExpense inherit properties and methods from the Expense class.
3. Polymorphism:
a. Polymorphism: It allows objects of different types to be treated as objects of a common superclass. For example, you can treat
both RecurringExpense and RegularExpense objects as Expense objects, enabling flexibility in method calls and code design.
4. Encapsulation:
a. Data Hiding and Encapsulation: Encapsulation restricts access to certain components of objects, preventing direct
modification. Private fields (username, password, etc.) are encapsulated within classes, and access is provided through public
methods.
2. HashMap:
a. HashMap: It's a part of the Java Collections Framework that stores key-value pairs. You've used HashMap<String, User> in
ExpenseManager to store user information with usernames as keys.
3. Iteration:
a. Iteration: It's the process of traversing through elements of a collection. You've used iteration to loop through expenses in
methods like calculateTotalExpenses to calculate the total expenses.
Additional Concepts:
1. Exception Handling:
a. Exception Handling: It's a mechanism to handle errors and exceptional situations gracefully. You may consider adding
exception handling mechanisms like try-catch blocks to deal with potential errors in user input or file operations.
import java.util.Date;
package com.example.project11.Model;
package com.example.project11.Security;
import com.example.project11.Service.ExpenseManager;
package com.example.project11.Security;
import com.example.project11.Service.ExpenseManager;
package com.example.project11.Security;
import java.util.ArrayList;
import java.util.List;
import com.example.project11.Model.Expense;
package com.example.project11.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.example.project11.Model.Expense;
import com.example.project11.Security.User;
public ExpenseManager() {
this.users = new HashMap<>();
}
public void addExpense(String username, String category, double amount, String description) {
User user = users.get(username);
if (user != null) {
Expense expense = new Expense(category, amount, description);
user.addExpense(expense);
}
}
package com.example.project11.Service;
import com.example.project11.Model.Expense;
import com.example.project11.Security.User;
import java.util.List;
package com.example.project11.Util;
import com.example.project11.Model.Expense;
import com.example.project11.Model.RegularExpense;
import com.example.project11.Model.RecurringExpense;
import com.example.project11.Security.User;
import com.example.project11.Security.Login;
import com.example.project11.Security.Register;
import com.example.project11.Security.Security;
import com.example.project11.Service.ExpenseManager;
import com.example.project11.Service.ExpenseService;
import java.util.List;
import java.util.Scanner;
while (true) {
System.out.println("\n1. Register\n2. Login\n3. Exit");
System.out.print("Choose an option: ");
int option = scanner.nextInt();
scanner.nextLine();
switch (option) {
case 1:
registerUser(scanner);
break;
case 2:
loginUser(scanner);
break;
case 3:
System.out.println("Exiting...");
System.exit(0);
default:
System.out.println("Invalid option!");
}
}
}
if (currentUser != null) {
System.out.println("Login successful!");
manageSession(scanner);
} else {
System.out.println("Invalid username or password!");
}
}
switch (option) {
case 1:
addExpense(scanner);
break;
case 2:
viewExpenses();
break;
case 3:
viewTotalExpenses();
break;
case 4:
currentUser = null;
return;
default:
System.out.println("Invalid option!");
}
}
}
switch (option) {
case 1:
addRegularExpense(scanner);
break;
case 2:
addRecurringExpense(scanner);
break;
case 3:
return;
default:
System.out.println("Invalid option!");
}
}