Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update developerguide and add assertions to transactionlist class #112

Merged
merged 4 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions data/carData.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Honda Civic | SZZ1579D | 150.0 | true
1 change: 1 addition & 0 deletions data/transactionData.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SZZ1579D | Apple | -1 | 11-12-2025
41 changes: 41 additions & 0 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,47 @@ Responsibility principle (SRP) or Separation of Concerns principle (SOC).
- Possibility that user might forget to update rental status
- Need to add new commands to update rental status (e.g. `mark-rented`)

### Implementation of Transaction Completion Management and Retrieval Features

To enhance the functionality of **CliRental**, we have implemented features that allow users to mark transactions as completed or uncompleted, list transactions based on their completion status, and find transactions by customer name. These features streamline the process of managing rental transactions, ensuring accurate tracking and easy retrieval of relevant data.

#### **1. Overview of Features**

- **Marking/Unmarking Transactions as Completed:**
- **Mark Completed:** Allows users to mark a specific transaction as completed, indicating that the rental process has been finalized.
- **Unmark Completed:** Enables users to revert a transaction's status from completed to uncompleted if needed.

- **Listing Transactions:**
- **List Completed Transactions:** Displays all transactions that have been marked as completed.
- **List Uncompleted Transactions:** Shows all transactions that are still pending completion.

- **Finding Transactions by Customer Name:**
- Facilitates the retrieval of all transactions associated with a specific customer, enabling efficient management and review.

#### **2. Design & Implementation**

The implementation of these features is encapsulated within the `TransactionList` class, which manages all transaction-related operations. Below is a detailed breakdown of the design and implementation strategies employed.

##### **a. Class-Level Design**

**`TransactionList` Class:**

- **Responsibilities:**
- Manage the list of all transactions.
- Provide functionalities to add, remove, update, and retrieve transactions based on various criteria.

- **Key Methods:**
- `markCompletedByTxId(String txId)`: Marks a transaction as completed.
- `unmarkCompletedByTxId(String txId)`: Marks a transaction as uncompleted.
- `printCompletedTransactions()`: Lists all completed transactions.
- `printUncompletedTransactions()`: Lists all uncompleted transactions.
- `findTxsByCustomer(String customer)`: Retrieves transactions associated with a specific customer.

**Design Considerations:**

- **Encapsulation:** The `transactionList` is maintained as a private static `ArrayList<Transaction>`, ensuring controlled access through public methods.
- **Data Integrity:** Assertions and exception handling are employed to maintain the integrity of transaction data during operations.

## Product scope
### Target user profile

Expand Down
38 changes: 38 additions & 0 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,44 @@ What would you like to do?
____________________________________________________________
```

### Adding a Transaction: `add-tx`

Adds a new rental transaction to the system.

**Format:** `add-transaction /tx [LICENSE_PLATE] /u [USERNAME] /d [DURATION_DAYS] /s [START_DATE]`

- **`/tx`**: License plate number of the car (format: `SXX####X`).
- **`/u`**: Username of the customer.
- **`/d`**: Rental duration in days.
- **`/s`**: Rental start date (format: `YYYY-MM-DD`).
- **Parameters must be in the specified sequence.**

**Example:** add-tx /p SZZ1579D /u John /d 15 /s 11-5-2025
Sample Response:
```
Transaction added:
[ ] TX2 | SZZ1579D | John | 15day(s)
Start Date: 2025-05-11
____________________________________________________________
```


### Listing All Transactions: `list-tx`

Displays all rental transactions in the system.

**Format:** `list-tx`

**Sample Response:**
```
Here are all the transactions:
1) [ ] TX1 | SZZ1579D | Apple | 1day(s)
Start Date: 2025-12-11
2) [ ] TX2 | SZZ1579D | John | 15day(s)
Start Date: 2025-05-11
____________________________________________________________```
```

## FAQ

**Q**: Is there any file saving system in place currently?
Expand Down
68 changes: 64 additions & 4 deletions src/main/java/transaction/TransactionList.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@

public class TransactionList {

// Ensure the transaction list is initialized properly
private static final ArrayList<Transaction> transactionList = new ArrayList<>();

public static void addTx(Transaction transaction) {
// Assert that the transaction is not null
assert transaction != null : "Transaction to add should not be null.";

String licensePlateNumber = transaction.getCarLicensePlate();
// Assert that the license plate number is not null
assert licensePlateNumber != null : "License plate number should not be null.";

if (!CarParser.isValidLicensePlateNumber(licensePlateNumber)) {
throw CarException.invalidLicensePlateNumber();
Expand All @@ -19,14 +25,30 @@ public static void addTx(Transaction transaction) {
if (!CarList.isExistingLicensePlateNumber(licensePlateNumber)){
throw CarException.licensePlateNumberNotFound();
}

// Assert that the license plate number is valid and exists before adding
assert CarParser.isValidLicensePlateNumber(licensePlateNumber)
&& CarList.isExistingLicensePlateNumber(licensePlateNumber)
: "License plate number must be valid and exist in CarList.";

transactionList.add(transaction);

// Assert that the transaction was added successfully
assert transactionList.contains(transaction) : "Transaction was not added to the list.";

CarList.markCarAsRented(licensePlateNumber);
System.out.println("Transaction added: ");
System.out.println(transaction);
}

public static void addTxWithoutPrintingInfo(Transaction transaction) {
// Assert that the transaction is not null
assert transaction != null : "Transaction to add should not be null.";

transactionList.add(transaction);

// Assert that the transaction was added successfully
assert transactionList.contains(transaction) : "Transaction was not added to the list.";
}

public static void printAllTransactions() {
Expand All @@ -40,6 +62,8 @@ public static void printAllTransactions() {
System.out.println("Here are all the transactions: ");

for (Transaction transaction : transactionList) {
// Assert that each transaction is not null
assert transaction != null : "Transaction in the list should not be null.";
System.out.println(index + ") " + transaction);
index++;
}
Expand All @@ -56,6 +80,8 @@ public static void printCompletedTransactions() {
System.out.println("Here are all the completed transactions: ");

for (Transaction transaction : transactionList) {
// Assert that each transaction is not null
assert transaction != null : "Transaction in the list should not be null.";
if(transaction.isCompleted()) {
System.out.println(index + ") " + transaction);
index++;
Expand All @@ -74,6 +100,8 @@ public static void printUncompletedTransactions() {
System.out.println("Here are all the uncompleted transactions: ");

for (Transaction transaction : transactionList) {
// Assert that each transaction is not null
assert transaction != null : "Transaction in the list should not be null.";
if(!transaction.isCompleted()) {
System.out.println(index + ") " + transaction);
index++;
Expand All @@ -82,21 +110,34 @@ public static void printUncompletedTransactions() {
}

public static void removeTxByTxId(String txId) {
// Assert that txId is not null
assert txId != null : "Transaction ID to remove should not be null.";

for (Transaction transaction : transactionList) {
if (transaction.getTransactionId().toLowerCase().equals(txId)) {
// Assert that each transaction is not null
assert transaction != null : "Transaction in the list should not be null.";
if (transaction.getTransactionId().equalsIgnoreCase(txId)) {
System.out.println("Transaction deleted: " + transaction);
transactionList.remove(transaction);

// Assert that the transaction was removed successfully
assert !transactionList.contains(transaction) : "Transaction was not removed from the list.";
return;
}
}
System.out.println("Transaction not found");
}

public static void findTxsByCustomer(String customer) {
// Assert that customer is not null
assert customer != null : "Customer name to find transactions should not be null.";

boolean found = false;
System.out.println("Transaction(s) by " + customer + " found:");
for (Transaction transaction : transactionList) {
if (transaction.getCustomer().toLowerCase().equals(customer)) {
// Assert that each transaction is not null
assert transaction != null : "Transaction in the list should not be null.";
if (transaction.getCustomer().toLowerCase().contains(customer)) {
found = true;
System.out.println(transaction);
}
Expand All @@ -107,30 +148,49 @@ public static void findTxsByCustomer(String customer) {
}

public static void markCompletedByTxId(String txId) {
// Assert that txId is not null
assert txId != null : "Transaction ID to mark as completed should not be null.";

for (Transaction transaction : transactionList) {
if (transaction.getTransactionId().toLowerCase().equals(txId)) {
// Assert that each transaction is not null
assert transaction != null : "Transaction in the list should not be null.";
if (transaction.getTransactionId().equalsIgnoreCase(txId)) {
transaction.setCompleted(true);
System.out.println("Transaction completed: " + transaction);

// Assert that the transaction is marked as completed
assert transaction.isCompleted() : "Transaction was not marked as completed.";
return;
}
}
System.out.println("Transaction not found");
}

public static void unmarkCompletedByTxId(String txId) {
// Assert that txId is not null
assert txId != null : "Transaction ID to unmark as completed should not be null.";

for (Transaction transaction : transactionList) {
if (transaction.getTransactionId().toLowerCase().equals(txId)) {
// Assert that each transaction is not null
assert transaction != null : "Transaction in the list should not be null.";
if (transaction.getTransactionId().equalsIgnoreCase(txId)) {
transaction.setCompleted(false);
System.out.println("Transaction set uncompleted: " + transaction);

// Assert that the transaction is marked as uncompleted
assert !transaction.isCompleted() : "Transaction was not unmarked as completed.";
return;
}
}
System.out.println("Transaction not found");
}

public static String transactionListToFileString(){

StringBuilder transactionData = new StringBuilder();
for (Transaction transaction : transactionList) {
// Assert that each transaction is not null
assert transaction != null : "Transaction in the list should not be null.";
transactionData.append(transaction.toFileString());
transactionData.append(System.lineSeparator());
}
Expand Down
Loading