Skip to content
Open
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
backend/node_modules/
frontend/node_modules/
frontend/dist/
.DS_Store
104 changes: 79 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,97 @@
# Cash Register

## The Problem
Creative Cash Draw Solutions is a client who wants to provide something different for the cashiers who use their system. The function of the application is to tell the cashier how much change is owed, and what denominations should be used. In most cases the app should return the minimum amount of physical change, but the client would like to add a twist. If the "owed" amount is divisible by 3, the app should randomly generate the change denominations (but the math still needs to be right :))
Cash register change calculator with:
- `backend` (Node.js + Express API + CLI file processor)
- `frontend` (React + Vite UI)

Please write a program which accomplishes the clients goals. The program should:
## Behavior
- Input format: one line per transaction, `owed,paid`
- Standard behavior: minimum number of denominations
- Twist behavior: if change owed (in cents) is divisible by `3`, denomination selection is randomized but total stays correct

1. Accept a flat file as input
1. Each line will contain the amount owed and the amount paid separated by a comma (for example: 2.13,3.00)
2. Expect that there will be multiple lines
2. Output the change the cashier should return to the customer
1. The return string should look like: 1 dollar,2 quarters,1 nickel, etc ...
2. Each new line in the input file should be a new line in the output file
Example input:

## Sample Input
```txt
2.12,3.00

1.97,2.00

3.33,5.00
```

## Sample Output
3 quarters,1 dime,3 pennies
Example output:

```txt
3 quarters,1 dime,3 pennies
3 pennies

1 dollar,1 quarter,6 nickels,12 pennies
```

## Project Structure

```txt
CashRegister/
backend/
src/
config/
services/
utils/
server.js
cli.js
test/
frontend/
src/
```

## Backend

Install dependencies:

```bash
cd backend
npm install
```

Run API:

```bash
npm start
```

Backend endpoints:
- `GET /api/health`
- `GET /api/config`
- `POST /api/change` with JSON body `{ "input": "2.12,3.00\n1.97,2.00" }`

Run tests:

```bash
npm test
```

Process a flat file from CLI:

```bash
npm run process-file -- ./path/to/input.txt
```

## Frontend

*Remember the last one is random
Install dependencies:

## The Fine Print
Please use whatever technology and techniques you feel are applicable to solve the problem. We suggest that you approach this exercise as if this code was part of a larger system. The end result should be representative of your abilities and style.
```bash
cd frontend
npm install
```

Please fork this repository. When you have completed your solution, please issue a pull request to notify us that you are ready.
Run UI:

Have fun.
```bash
npm run dev
```

## Things To Consider
Here are a couple of thoughts about the domain that could influence your response:
The Vite dev server proxies `/api/*` to `http://localhost:4000`.

* What might happen if the client needs to change the random divisor?
* What might happen if the client needs to add another special case (like the random twist)?
* What might happen if sales closes a new client in France?
## Extensibility Notes
- Random rule divisor is centralized in `backend/src/config/rules.js`.
- Denominations are centralized in `backend/src/config/denominations.js`.
- Additional special-case behaviors can be introduced in `backend/src/services/changeCalculator.js` as rule modules.
- Supporting a new currency/locale can be done by adding a denomination config and amount parser strategy.
Loading