Coder Social home page Coder Social logo

pretty-prices's Introduction

Pretty Prices

Problem

Converting between currencies can result in funny-looking results.

Suppose the exchange rate is 1.34 CA$ / US$. A product that costs a familiar US$ 9.99, will cost CA$ 13.39.

US$  9.99
 *   1.34
 -------
CA$ 13.39

Shoppers aren't always used to prices ending in 0.39!

How can we round prices to look "normal"?

Goal

Extend PriceConverter.java to return prices rounded...

  1. up to the nearest quarter (ending in .00, .25, .50, .75)
    • e.g. 9.99 * 1.34 = 13.39 --> 13.50
  2. up or down to the nearest quarter. (Have the user specify.)
    • e.g. rounding down 9.99 * 1.34 = 13.39 --> 13.25
  3. up to the nearest user-provided multiple (e.g., nearest 0.10, 0,05, 0.20, ...)
    • e.g. rounding up to nearest 0.20 9.99 * 1.34 = 13.39 --> 13.40
  4. up to end in .99 cents (e.g. 13.39 -> 13.99)
    • e.g. 9.99 * 1.34 = 13.39 --> 13.99
    • Note: this is not the same as rounding up to a multiple of 0.99 (why?)
  5. up to end in any amount
    • e.g. round to end in 0.13 9.99 * 1.34 = 13.39 --> 14.13

If you've done all the above, PriceConverter.java should be able to...

  • round either up or down
  • to a multiple of X
  • or to an ending of X

Useful commands

  • Test: mvn test
  • Build: mvn compile
  • Run: mvn exec:java -Dexec.mainClass="com.shopify.prettyprices.Main"

Alternately, without Maven magic, from src/main/java directory:

  • build: javac com/shopify/prettyprices/*.java
  • run: java com.shopify.prettyprices.Main

pretty-prices's People

Contributors

sjswoboda avatar cpauderis avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.