This project is a Dropwizard-based application that calculates the minimum number of coins needed to make a given amount. The application exposes a REST API endpoint to perform the calculation.
Coin denomination must be one of the following values [0.01, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10, 50, 100, 1000]
Output: A list of minimum number of coins in ascending order You can assume that you have infinite number of coins for each denomination
Input: Target amount: 7.03 Coin denominator: [0.01, 0.5, 1, 5, 10] Output: [0.01, 0.01, 0.01, 1, 1, 5]
Input: Target amount: 103 Coin denominator: [1, 2, 50] Output: [1, 2, 50, 50]
- Java 17 or later
- Gradle 8.8 or later
To build the project, run the following command:
./gradlew build
This will compile the source code, run the tests, and create a JAR file in the libs directory.
To run the application without Docker, use the following command:
java -jar coinchange-backend/build/libs/coinchange-1.0.1-all.jar server coinchange-backend/resources/config.yml
To run the application with Docker, follow these steps:
- Build the Docker image:
docker build -t coinchange-app .
- Run the Docker container:
docker run -p 8080:8080 -p 8081:8081 coinchange-app
The application exposes the following endpoint:
-
POST /coin-change: Calculates the minimum number of coins needed to make the given amount.
{
"targetAmount": 123.45,
"coinDenominations": [0.01, 0.05, 0.1, 0.25, 1.0]
}
{
"coinChange": [1.0, 0.25, 0.1, 0.1, 0.01]
}
The application configuration is specified in the config.yml file. The configuration includes settings for the server and logging.
server:
applicationConnectors:
- type: http
port: 8080
adminConnectors:
- type: http
port: 8081
loggingConfig: ./resources/logback.xml
The logging configuration is specified in the logback.xml file. The configuration includes settings for console and file appenders.
To run the tests, use the following command:
./gradlew test
The test results will be available in the test directory.
This project is licensed under the Apache License, Version 2.0. See the LICENSE file for details.
This README.md
file provides an overview of the project, instructions for building and running the application with and without Docker, details about the API endpoint, configuration, logging, testing, and licensing.
This project is a React-based frontend application that interacts with a Dropwizard backend to calculate the minimum number of coins needed to make a given amount. The application dynamically filters available coin denominations based on the target amount entered by the user.
- Node.js (version 14 or later)
- npm (version 6 or later)
In the project directory, you can run:
Runs the app in the development mode.
Open http://localhost:3000 to view it in your browser.
The page will reload when you make changes.
You may also see any lint errors in the console.
Launches the test runner in the interactive watch mode.
See the section about running tests for more information.
Builds the app for production to the build
folder.
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.
Your app is ready to be deployed!
See the section about deployment for more information.
Note: this is a one-way operation. Once you eject
, you can't go back!
If you aren't satisfied with the build tool and configuration choices, you can eject
at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except eject
will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
You don't have to ever use eject
. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However, we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
The Coin Change Calculator allows users to input a target amount and dynamically filters the available coin denominations based on the input. The filtered denominations are then sent to the backend to calculate the minimum number of coins needed.
- Target Amount Input: Users can input the target amount they want to calculate the coin change for.
- Dynamic Coin Denominations: The available coin denominations are dynamically filtered based on the target amount.
- Calculate Coin Change: The filtered denominations are sent to the backend to calculate the minimum number of coins needed.
- Error Handling: Displays error messages if the calculation fails.
- Clear Coin Change: Clears the calculated coin change when the target amount is cleared.
- Enter Target Amount: Input the target amount in the "Target Amount" field.
- View Available Coin Denominations: The available coin denominations will be displayed and dynamically filtered based on the target amount.
- Calculate Coin Change: Click the "Calculate" button to calculate the minimum number of coins needed.
- View Coin Change: The calculated coin change will be displayed below the button.
- Clear Coin Change: Clear the target amount to reset the coin change calculation.