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

Mini Project Documentation

The Roommate Expense Sharing Application is a JavaFX-based tool designed to help roommates track and manage shared expenses efficiently. It allows users to add roommates, record transactions, log payments, and calculate individual balances, ensuring transparency in cost-sharing. Future enhancements could include database integration for data persistence, custom expense splits, and mobile compatibility.

Uploaded by

yokeshkumar1910
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Mini Project Documentation

The Roommate Expense Sharing Application is a JavaFX-based tool designed to help roommates track and manage shared expenses efficiently. It allows users to add roommates, record transactions, log payments, and calculate individual balances, ensuring transparency in cost-sharing. Future enhancements could include database integration for data persistence, custom expense splits, and mobile compatibility.

Uploaded by

yokeshkumar1910
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

EXP NO: 11 JAVA EXPENSE SHARING APPLICATION

PAGE NO:
DATE:

1. Introduction
The Roommate Expense Sharing Application is designed to simplify expense
tracking and sharing among roommates. Built using JavaFX, it provides an intuitive graphical
interface to manage shared costs effectively. Users can add roommates, record expenses, set a
manual total for group expenses, log payments, and calculate balances. The application also
generates summaries showing how much each person owes or is owed, ensuring transparency
in cost-sharing.

2. System Requirements
2.1 Hardware Requirements
 RAM: Minimum 4GB
 Processor: Intel Core i3 or equivalent
 Operating System: Windows, macOS, or Linux
2.2 Software Requirements
 Java Development Kit (JDK): Version 8 or higher
 JavaFX SDK: Included in most modern JDKs
 Integrated Development Environment (IDE): IntelliJ IDEA, Eclipse, or NetBeans
The above requirements ensure smooth operation of the application without performance
issues.

3. Application Features
3.1 Adding Roommates
Users can add roommates by entering their names and clicking the "Add Person" button. The
application prevents duplicate entries, ensuring that each roommate has a unique identifier.
3.2 Recording Transactions
Expenses can be recorded by specifying the amount and selecting the person who paid. The
system stores these transactions and displays them in the transaction list.
3.3 Manual Total Expenses
Users can set a manual total expense value if the total is known beforehand. This overrides
the dynamically calculated total.
3.4 Payment Recording
Payments made by individuals can be logged, which reduces their balances. The payment
system helps track how much each person has contributed toward settling their share.
3.5 Calculating Balances
The "Calculate Share" button computes balances for all roommates based on expenses and
payments. It displays:
 Total group expenses
 Individual contributions
 Balances owed or owed to each person

4. User Interface Design


The application uses JavaFX to create a clean, intuitive layout with the following sections:
4.1 Top Panel
 Add Person Panel: Contains a text field for entering names and a button to add
roommates.
 Add Transaction Panel: Allows users to record expenses, specifying the payer and
amount.
 Manual Total Panel: Provides a text field for entering a total expense value and a
button to set it.
4.2 Middle Panel
 Payment Panel: Lets users record payments made by individuals.
 List of Roommates: Displays the names of all added roommates.
 Transaction List: Shows all recorded transactions.
4.3 Bottom Panel
 Summary Area: Displays a detailed breakdown of expenses, contributions, and
balances.
 Calculate Button: Triggers the calculation of shares.

5. Application Architecture
5.1 Main Class
The main class initializes the user interface and processes user inputs. It handles the
following:
 Adding and managing roommates
 Recording expenses and payments
 Calculating and displaying summaries
5.2 Person Class
The Person class represents a roommate and includes:
 Name of the roommate
 List of transactions
 Payments made
 Methods to calculate total expenses and balances
5.3 Transaction Class
The Transaction class represents an expense and includes:
 Amount of the expense
 Person who paid for the expense
5.4 Data Flow
 User inputs are processed in the ExpenseSharingAppFX class.
 Data is stored and manipulated using the Person and Transaction classes.
 Outputs, such as summaries and lists, are updated dynamically.

6. Workflow
6.1 Adding a Roommate
1. Enter the name in the "Enter person's name" field.
2. Click the "Add Person" button.
3. The roommate is added to the list and becomes selectable in the dropdowns.
6.2 Recording an Expense
1. Enter the expense amount in the field.
2. Select the payer from the dropdown menu.
3. Click the "Add Transaction" button to save the expense.
6.3 Setting a Manual Total
1. Enter the total expense value in the provided field.
2. Click the "Set Total Expense" button.
3. The manual total is applied, overriding the dynamic calculation.
6.4 Recording a Payment
1. Enter the payment amount in the text field.
2. Select the payer from the dropdown.
3. Click the "Record Payment" button to save the payment.
6.5 Calculating Balances
1. Click the "Calculate Share" button.
2. View the detailed breakdown in the summary area.

7. Error Handling
7.1 Input Validation
 Ensures that text fields are not empty and values are correctly formatted.
 Checks for duplicate names when adding roommates.
7.2 Alerts
 Error alerts notify users of invalid inputs or missing data.
 Success alerts confirm actions like adding a person or recording a payment.
7.3 Robustness
The application handles edge cases, such as:
 No roommates added
 Zero expenses recorded
 Negative or invalid amounts

8. Future Enhancements

While the Roommate Expense Sharing Application is fully functional, there are several ways
it can be improved to offer more features and better user experience:

1. Data Persistence with Database Integration


Currently, the application operates in memory, meaning data is lost when the
application is closed. Integrating a database like SQLite, MySQL, or PostgreSQL
would allow the application to store and retrieve data persistently. This would enable
users to:
1. Save roommate information, transactions, and payments for future use.
2. Access historical data for analysis or reference.
3. Share a common database across devices for collaborative expense tracking.
2. Custom Splits
Introduce a feature that lets users define custom expense-sharing ratios. This would be
useful in scenarios where expenses are not equally split, such as when one roommate
uses more resources than others.
3. Reports
Add functionality to generate detailed expense and payment reports in PDF or Excel
format. Users could save or share these reports for record-keeping or dispute
resolution.
4. Mobile Compatibility
Extend the application to mobile platforms using JavaFX for Android or Kotlin/Java.
This would allow users to track expenses and manage balances on their smartphones,
increasing accessibility.
5. Enhanced User Interface
Modernize the UI with improved visuals, responsive design, and advanced controls
like charts to display expense trends and payment distributions.
Program:

package com.example.expensetracker;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.Stage;
import java.util.ArrayList;

public class ExpenseSharingAppFX extends Application {


private ArrayList<Person> persons;
private ListView<String> transactionListView;
private TextField personNameField;
private TextField expenseAmountField;
private TextField manualTotalField;
private TextField paymentAmountField;
private ComboBox<String> expensePaidByComboBox;
private ComboBox<String> paymentPayerComboBox;
private Button addPersonButton, addTransactionButton, calculateButton,
setManualTotalButton, recordPaymentButton;
private TextArea summaryArea;
private double manualTotalExpenses = -1;
private ListView<String> personListView;

@Override
public void start(Stage primaryStage) {
persons = new ArrayList<>();
primaryStage.setTitle("Roommate Expense Sharing System");

BorderPane mainLayout = new BorderPane();


mainLayout.setPadding(new Insets(10));

VBox addPersonPanel = new VBox(10);


addPersonPanel.setPadding(new Insets(10));
personNameField = new TextField();
personNameField.setPromptText("Enter person's name");
addPersonButton = new Button("Add Person");
addPersonButton.setOnAction(e -> addPerson());
addPersonPanel.getChildren().addAll(new Label("Add Person:"), personNameField,
addPersonButton);

VBox addTransactionPanel = new VBox(10);


addTransactionPanel.setPadding(new Insets(10));
expenseAmountField = new TextField();
expenseAmountField.setPromptText("Enter expense amount");
expensePaidByComboBox = new ComboBox<>();
addTransactionButton = new Button("Add Transaction");
addTransactionButton.setOnAction(e -> addTransaction());
addTransactionPanel.getChildren().addAll(
new Label("Add Transaction:"),
expenseAmountField,
new Label("Paid By:"),
expensePaidByComboBox,
addTransactionButton
);

VBox manualTotalPanel = new VBox(10);


manualTotalPanel.setPadding(new Insets(10));
manualTotalField = new TextField();
manualTotalField.setPromptText("Enter total expense amount");
setManualTotalButton = new Button("Set Total Expense");
setManualTotalButton.setOnAction(e -> setManualTotalExpense());
manualTotalPanel.getChildren().addAll(
new Label("Set Manual Total:"),
manualTotalField,
setManualTotalButton
);

VBox paymentPanel = new VBox(10);


paymentPanel.setPadding(new Insets(10));
paymentAmountField = new TextField();
paymentAmountField.setPromptText("Enter payment amount");
paymentPayerComboBox = new ComboBox<>();
recordPaymentButton = new Button("Record Payment");
recordPaymentButton.setOnAction(e -> recordPayment());
paymentPanel.getChildren().addAll(
new Label("Record Payment:"),
paymentAmountField,
new Label("Payer:"),
paymentPayerComboBox,
recordPaymentButton
);

transactionListView = new ListView<>();


transactionListView.setPrefHeight(150);

personListView = new ListView<>();


personListView.setPrefHeight(150);
VBox calculatePanel = new VBox(10);
calculatePanel.setPadding(new Insets(10));
summaryArea = new TextArea();
summaryArea.setEditable(false);
summaryArea.setPrefHeight(200);
calculateButton = new Button("Calculate Share");
calculateButton.setOnAction(e -> calculateShare());
calculatePanel.getChildren().addAll(new Label("Summary:"), summaryArea,
calculateButton);

HBox topPanel = new HBox(10, addPersonPanel, addTransactionPanel,


manualTotalPanel);
HBox middlePanel = new HBox(10, paymentPanel, personListView,
transactionListView);

mainLayout.setTop(topPanel);
mainLayout.setCenter(middlePanel);
mainLayout.setBottom(calculatePanel);

Scene scene = new Scene(mainLayout, 800, 600);


primaryStage.setScene(scene);
primaryStage.show();
}

private void addPerson() {


String name = personNameField.getText().trim();
if (!name.isEmpty()) {
for (Person person : persons) {
if (person.getName().equalsIgnoreCase(name)) {
showAlert("Error", "Person already exists.");
return;
}
}
Person newPerson = new Person(name);
persons.add(newPerson);
expensePaidByComboBox.getItems().add(name);
paymentPayerComboBox.getItems().add(name);
personListView.getItems().add(name);
personNameField.clear();
showAlert("Success", "Person added successfully.");
} else {
showAlert("Error", "Please enter a valid name.");
}
}

private void addTransaction() {


try {
double amount = Double.parseDouble(expenseAmountField.getText().trim());
if (amount <= 0) {
showAlert("Error", "Amount must be a positive value.");
return;
}
String paidBy = expensePaidByComboBox.getValue();
if (paidBy == null) {
showAlert("Error", "Please select a person who paid.");
return;
}
Person payer = getPerson(paidBy);
if (payer != null) {
Transaction newTransaction = new Transaction(amount, payer);
payer.addTransaction(newTransaction);
transactionListView.getItems().add(paidBy + " paid: $" + amount);
expenseAmountField.clear();
} else {
showAlert("Error", "Person not found.");
}
} catch (NumberFormatException e) {
showAlert("Error", "Please enter a valid amount.");
}
}

private void setManualTotalExpense() {


try {
double manualTotal = Double.parseDouble(manualTotalField.getText().trim());
if (manualTotal < 0) {
showAlert("Error", "Total expense must be a positive number.");
return;
}
manualTotalExpenses = manualTotal;
manualTotalField.clear();
showAlert("Success", "Manual total expense set to $" + manualTotal);
} catch (NumberFormatException e) {
showAlert("Error", "Please enter a valid total expense amount.");
}
}

private void recordPayment() {


try {
double payment = Double.parseDouble(paymentAmountField.getText().trim());
if (payment <= 0) {
showAlert("Error", "Payment amount must be positive.");
return;
}
String payerName = paymentPayerComboBox.getValue();
if (payerName == null) {
showAlert("Error", "Please select a payer.");
return;
}
Person payer = getPerson(payerName);
if (payer != null) {
payer.addPayment(payment);
showAlert("Success", payerName + " paid $" + payment + " towards their
balance.");
paymentAmountField.clear();
}
} catch (NumberFormatException e) {
showAlert("Error", "Please enter a valid payment amount.");
}
}

private void calculateShare() {


if (persons.isEmpty()) {
showAlert("Error", "No persons added. Please add persons.");
return;
}

double totalExpenses = 0;
if (manualTotalExpenses >= 0) {
totalExpenses = manualTotalExpenses;
} else {
for (Person person : persons) {
totalExpenses += person.getTotalExpenses();
}
}

double equalShare = totalExpenses / persons.size();

StringBuilder summary = new StringBuilder("Total Expenses: $" + totalExpenses + "\


n");
summary.append("Each person should contribute: $" + String.format("%.2f",
equalShare) + "\n\n");

summary.append("Individual Contributions:\n");
for (Person person : persons) {
double totalPaid = person.getTotalExpenses();
summary.append(person.getName() + " paid: $" + String.format("%.2f", totalPaid) +
"\n");
}

summary.append("\nBalances:\n");
for (Person person : persons) {
double balance = person.getBalance(equalShare);
if (balance > 0) {
summary.append(person.getName() + " is owed: $" + String.format("%.2f",
balance) + "\n");
} else if (balance < 0) {
summary.append(person.getName() + " owes: $" + String.format("%.2f", -balance)
+ "\n");
} else {
summary.append(person.getName() + " is settled.\n");
}
}
summaryArea.setText(summary.toString());
}

private Person getPerson(String name) {


for (Person person : persons) {
if (person.getName().equalsIgnoreCase(name)) {
return person;
}
}
return null;
}

private void showAlert(String title, String message) {


Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle(title);
alert.setContentText(message);
alert.showAndWait();
}

public static void main(String[] args) {


launch(args);
}
}
OUTPUT:

Conclusion:
The Roommate Expense Sharing Application provides a practical solution for tracking
and managing shared expenses. It is intuitive, lightweight, and highly functional, making it an
excellent choice for roommates who want a fair and transparent way to divide costs. With
potential enhancements, the application can evolve into a more robust and versatile tool for
personal finance management.

You might also like