Coder Social home page Coder Social logo

tp0124's Introduction

tp0124

Thanks for looking at my submission!

Best regards, Tony

Dependencies

This uses the latest JDK 21, gradle, picocli (for the cli), and a test logger. I believe Java record type is the newest dependency used here. This likely will work back to JDK 14 with minimal changes but I haven't tested older versions.

Building

This is a standard gradle project. You can build with the usual gradle commands. You can generate a binary for usual cli calls with:

(base) tony@Tonys-MacBook-Air tp0124 % ./gradlew clean build distZip distTar installDist

> Task :app:test

  checkout.AccountingTest

    ✔ testSkipWeekdays()
    ✔ testSkipWeekends()
    ✔ testSkipHolidays()
    ✔ testChargeEveryDay()
    ✔ testSkipHolidaysWeekday()
    ✔ testSkipHolidaysWeekend()
    ✔ testSkipHolidaysDoubled()

  checkout.AppTest

    ✔ testAppDefaults()

  checkout.CheckoutTest

    ✔ testExceptionsCode()
    ✔ testExceptionsDays()
    ✔ testValid()
    ✔ testExceptionsCheckout()
    ✔ testExceptionsPercent()

  checkout.RentalAgreementTest

    ✔ testRentalAgreement()

  checkout.ToStringTest

    ✔ testToString()
    ✔ testAsDollars()
    ✔ testAsPercent()

  checkout.holiday.NearestHolidayTest

    ✔ testJulyFourth()

  checkout.holiday.RelativeHolidayTest

    ✔ testLaborDay()
    ✔ testThanksgiving()

  checkout.tables.HolidaysTest

    ✔ testHolidays()

  checkout.tables.ToolTypesTest

    ✔ testToolTypes()

  checkout.tables.ToolsTest

    ✔ testTools()

  23 passing (805ms)


BUILD SUCCESSFUL in 3s
11 actionable tasks: 11 executed

Demo

It's possible to run and pass in arguments with the gradle command:

./gradlew run --args="-h"

However, you can also reference the generated bin directly:

(base) tony@Tonys-MacBook-Air tp0124 % ./app/build/install/app/bin/app -h
Usage: checkout [-hV] [-c=<checkoutDate>] [-d=<numDays>] [-p=<percentDiscount>]
                [-t=<code>]
Generates the rental agreement.
  -c, --checkout=<checkoutDate>
                         Check out date, MM/DD/YYYY format
  -d, --days=<numDays>   Rental day count - The number of days for which the
                           customer wants to rent the tool. (e.g. 4 days)
  -h, --help             Show this help message and exit.
  -p, --percent=<percentDiscount>
                         Discount percent - As a whole number, 0-100 (e.g. 20 =
                           20%)
  -t, --tool=<code>      Tool code
  -V, --version          Print version information and exit.

I prefer the second approach with the generated binary, as it displays colorized output which is lost via gradle.

An example, checkout call:

(base) tony@Tonys-MacBook-Air tp0124 % ./app/build/install/app/bin/app -d 1000 -t JAKR -p 33 -c 07/01/34


Tool code: JAKR
Tool type: Jackhammer
Tool brand: Ridgid
Rental days: 1000
Check out date: 07/01/34
Due date: 03/27/37
Daily rental charge: $2.99
Charge days: 708
Pre-discount charge: $2,116.92
Discount percent: 33%
Discount amount: $698.58
Final charge: $1,418.34

We also have helpful error messages. See what happens with a negative percent:

(base) tony@Tonys-MacBook-Air tp0124 % ./app/build/install/app/bin/app -d 1000 -t JAKR -p -1 -c 07/01/34
Invalid value for option 'Discount percent': '-1' is not an int in [0, 100].
Usage: checkout [-hV] [-c=<checkoutDate>] [-d=<numDays>] [-p=<percentDiscount>]
                [-t=<code>]
Generates the rental agreement.
  -c, --checkout=<checkoutDate>
                         Check out date, MM/DD/YYYY format
  -d, --days=<numDays>   Rental day count - The number of days for which the
                           customer wants to rent the tool. (e.g. 4 days)
  -h, --help             Show this help message and exit.
  -p, --percent=<percentDiscount>
                         Discount percent - As a whole number, 0-100 (e.g. 20 =
                           20%)
  -t, --tool=<code>      Tool code
  -V, --version          Print version information and exit.

tp0124's People

Contributors

toperkin avatar

Watchers

 avatar  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.