warming up your workspace

Java practice in Java

Browse the rooms before signing in. Opening a room requires an account and follows your existing access. Practice does not issue certificates.

  • Clean the Input

    Parse s with Integer.parseInt. Return fallback if parsing throws NumberFormatException, including null, whitespace-surrounded text and values outside int range. Do not trim in this helper.

    catching. Free room.

  • Score the Password

    Return one point for UTF-16 length at least 8, one if any char satisfies Character.isDigit, and one if any char satisfies Character.isUpperCase. Each category scores at most once. Null or empty returns 0. This three-rule exercise is not a security estimate of password strength.

    control. Free room.

  • Shrink the Fraction

    Return the greatest common divisor of nonnegative int inputs with Euclid's remainder algorithm. gcd(a, 0) is a; define gcd(0, 0) as 0. The helper supplies the divisor used when simplifying a fraction.

    methods. Free room.

  • Steps to One

    For a positive starting long, repeatedly halve an even value or replace an odd value with 3*n+1 until reaching 1. Return the number of steps, with steps(1)=0. Inputs are restricted to sequences that reach 1 without overflowing long and whose step count fits int; general Collatz termination is not proven.

    control. Free room.

  • Dispatch the Sound

    Count array elements equal to 1. Other integer codes are not dogs; empty input returns 0. This encoded-data exercise does not call Animal.sound() or create subclasses.

    dispatch. Account access required.

  • Guard the Balance

    For a nonnegative balance, return true exactly when amount is positive and no greater than balance. This predicate checks permission; it does not mutate an account.

    encapsulation. Account access required.

  • Hash the Pair

    Return 31 * a + b using Java int arithmetic, including its normal wraparound. This is a pair-hash calculation; distinct pairs are allowed to collide. Do not claim the result is a unique ID or bucket index.

    equals. Account access required.

  • The Equal Contract

    Return 31 * a + b using Java int arithmetic, including its normal wraparound. This is a pair-hash calculation; distinct pairs are allowed to collide. Do not claim the result is a unique ID or bucket index.

    equals. Account access required.

  • Bucket the Keys

    Given bucket IDs and a positive bucket count n, return the largest number of occurrences assigned to one bucket. Every ID is in 0..n-1. An empty array returns 0; do not change it.

    hashmap. Account access required.

  • Double the Capacity

    A teaching list starts with capacity 4 and size 0. Just before an append that would exceed capacity, double the capacity. Return capacity after adds appends for 0 <= adds <= 1073741824. Capacity remains 4 for zero through four appends. This doubling policy belongs to our teaching list, not the public JDK ArrayList contract.

    arraylist. Account access required.

  • Grow the List

    A teaching list starts with capacity 4 and size 0. Just before an append that would exceed capacity, double the capacity. Return capacity after adds appends for 0 <= adds <= 1073741824. Capacity remains 4 for zero through four appends. This doubling policy belongs to our teaching list, not the public JDK ArrayList contract.

    arraylist. Account access required.

  • The PECS Sum

    Accept List<? extends Number> and sum each non-null element's doubleValue in encounter order. An empty list returns 0.0. Support Integer, Double and other Number subtypes; do not change the list.

    wildcards. Account access required.

  • Audit the Import

    For each row, trim surrounding characters using String.trim(), then parse a signed decimal int. Sum valid values and count invalid rows, including null or out-of-range text. Return exactly "sum=N errors=E". The accumulated sum fits int; do not modify the rows.

    validation. Account access required.

  • Drive the State

    Start in "draft". Process non-null event strings in order: "pay" changes draft to paid; "ship" changes paid to shipped. Ignore every other event or invalid/repeated transition. Return the final state; empty input stays draft.

    state. Account access required.

  • Price by Strategy

    Compute base * qty. If qty >= 10, charge 90 percent of that line subtotal, truncating toward zero; otherwise charge the subtotal. base and qty are nonnegative and the undiscounted subtotal fits int. Use a long intermediate for the percentage.

    strategy. Account access required.

  • Stack the Decorators

    Return the number of nonempty subsets of features: 2^features - 1. features is in 0..30. This model counts unordered on/off feature combinations, not wrapper order or every possible object-oriented design.

    decorator. Account access required.

  • All or Nothing

    The flags encode operation outcomes: zero means failure and any nonzero value means success. Return true if no flag is zero, including empty input, and false otherwise. This exercise decides a commit outcome from flags; actual apply/revert rollback is implemented in the main project.

    workflow. Account access required.

  • Ring It Up

    The array alternates priceCents, quantity, priceCents, quantity. Sum every line's price times quantity and return the basket total. The array has even length, prices and quantities are nonnegative, and all subtotals and their sum fit int. Empty input returns 0. This exercise totals a basket; the main project assembles the full engine.

    engine. Account access required.

  • Run the Pipeline

    Select non-null words whose original UTF-16 length is greater than 3. Uppercase each selected word with Locale.ROOT and sum the resulting UTF-16 lengths. Preserve duplicates; empty input returns 0. Case conversion can expand text. Any equivalent implementation of this calculation is valid.

    build-pipe. Account access required.

  • Stream the Squares

    Return the exact long sum of squares from 1 through n, with 0 for n <= 0. Supported n is at most 3024616 so the sum fits long. Widen before multiplying; IntStream.rangeClosed(...).mapToLong(...).sum() is one suitable approach.

    real-streams. Account access required.