Featured resource
2026 Tech Forecast
2026 Tech Forecast

1,500+ tech insiders, business leaders, and Pluralsight Authors share their predictions on what’s shifting fastest and how to stay ahead.

Download the forecast
  • Lab
    • Libraries: If you want this lab, consider one of these libraries.
    • Core Tech
Labs

Java Base Camp: Temperature Math

In this lab, you'll work on a Himalayan expedition's field toolkit for tracking temperatures at Base Camp, Camp 1, Camp 2, and the Summit. Sensors report raw readings in mixed units and formats, and the expedition doctor needs a reliable Java program that converts scales correctly, never silently truncates a life-safety reading, and produces a daily report climbers can trust before they leave the tent.

Lab platform
Lab Info
Level
Beginner
Last updated
Dec 05, 2026
Duration
45m

Contact sales

By clicking submit, you agree to our Privacy Policy and Terms of Use, and consent to receive marketing emails from Pluralsight.
Table of Contents
  1. Challenge

    Step 1: Orientation to the base camp temperature toolkit

    Welcome to the base camp temperature toolkit

    Four camps up the mountain — Base Camp, Camp 1, Camp 2, and the Summit — each report a temperature reading every morning from a slightly different sensor. Some sensors report whole degrees, some report fractions, some report Fahrenheit, and none of them agree on how to format a number. The expedition doctor needs one Java program that takes all of that mismatched input and turns it into a report she can trust before anyone leaves the tent.

    Over the next four steps you will build that program piece by piece: first the raw readings, then the unit conversions, then the statistics that summarize a day's data, and finally the report that ties it all together. ## Project layout

    Your code lives under src/main/java/lab/. Four files matter, one per step:

    • Readings.java (Step 2) — stores raw sensor values as the correct primitive types.
    • Conversions.java (Step 3) — static methods that convert between Celsius and Fahrenheit and round the result deliberately.
    • Statistics.java (Step 4) — overloaded methods that average and format either whole-degree or fractional readings, plus a wind-chill calculation that leans on careful variable scope.
    • Report.java (Step 5) — calls into the other three files to print the full daily report.

    Each file already compiles; the methods you'll complete are marked with // TODO: Task <n> comments. A test file per step checks the exact behavior each method must produce. ## Why the small stuff matters here

    A mountaineering temperature tool is exactly the kind of program where Java's strictness about types pays off. An int that should have been a long silently overflows after enough sensor readings. A cast written in the wrong place rounds a reading toward zero instead of to the nearest degree — the difference between reporting −24°C and −25°C, which is the difference between SAFE and DANGER in this lab's safety flag. A local variable declared in the wrong scope can quietly shadow another one with the same name and corrupt a calculation without ever failing to compile.

    None of this is abstract theory — it is exactly what you will practice building, one file at a time, starting with Readings.java in the next step.

    info> If you get stuck, you can refer to the provided solution code for each task, available in the solution folder.

  2. Challenge

    Step 2: Record temperature readings with primitives and safe casts

    Step 2: Primitives and safe casts in Readings.java

    Readings.java is where raw sensor values first enter the program. Choosing the right primitive type here — int for a whole-degree count, float for a fractional part, long for a running total that could exceed int range — determines whether every later calculation is trustworthy. Start with baseCampCelsius(), which combines a whole-degree reading and a fractional reading into one Celsius value. ## Casts you can see

    Java will convert a double to an int for you if you ask it to with a cast — but it always truncates toward zero, never rounds. For a life-safety reading, silently chopping off .6 of a degree is not acceptable. The fix is to make the rounding explicit: call Math.round on the full-precision value first, then cast its long result to int. That way the only truncation in the code is the one you asked for, and it happens after rounding, not instead of it. ## Literal suffixes and var

    A plain integer literal like 12 is an int by default, and 5.5 is a double by default. When you need a long or a float literal instead, you say so with a suffix: 12L, 5.5f. This matters when you're accumulating a whole batch of sensor readings — without the L, a total literal is still an int and can overflow. var doesn't change any of this; it just lets the compiler infer the concrete type from the expression on the right, so var total = 0L is still exactly a long, not something looser.

  3. Challenge

    Step 3: Build static conversion methods for camp temperatures

    Step 3: Turning inline math into static methods

    Step 2 computed a Fahrenheit conversion inline, right inside Readings.java. That works once, but every camp needs the same formula, and duplicating it invites a typo in one copy that nobody notices. Conversions.java extracts that formula into a static method with a typed parameter and a typed return, so every call site — now and later in Step 5 — shares the exact same, tested math. ## The inverse conversion

    Not every sensor reports Celsius. Some report Fahrenheit directly, and the report generator needs to normalize everything to Celsius internally before comparing camps. The inverse formula runs the same idea in reverse order: subtract the Fahrenheit offset first, then scale — get the order backwards and every converted value is wrong, even though the code still compiles and runs without error. ## One shared, explicit rounding step

    Both conversions in this file eventually need to hand back a whole-degree reading for display. Rather than rounding twice with slightly different code, both methods should be able to call one shared roundToWholeDegree helper. The technique is the same one from Task 2.2: round the double with Math.round, then cast the resulting long down to int on purpose, so the narrowing is a decision you made, not a side effect of the return type.

  4. Challenge

    Step 4: Overload statistics methods and manage nested scope

    Step 4: One method name, two data shapes

    Some camps log their day's readings as whole-degree ints, others as fractional doubles. Writing averageInts and averageDoubles as separate names would work, but it forces every caller to know which array type it has before it can even ask for an average. Method overloading lets Statistics.java expose a single name, average, with two implementations — the compiler picks the right one based on the argument type you pass. ## Overloading a formatter, too

    The same idea applies to display text: a whole-degree reading should print as "12°", but a fractional reading should print with one decimal place, like "12.3°". Rather than making every caller branch on the type first, formatReading is overloaded the same way average was — one version per parameter type, both returning the same kind of string. ## Scope, blocks, and shadowing

    Every { } in Java opens a new scope, and a local variable declared inside one is invisible once that block closes. That's normally a safety feature — until two blocks each declare a variable with the same name for a different purpose, and the wrong one gets read. windChillAdjustedSwing computes an intermediate wind-adjusted low inside a nested block, then uses it, by name, in a calculation outside that block. Getting the boundaries right is the difference between a correct swing and a compile error — or worse, a value that's silently wrong.

  5. Challenge

    Step 5: Assemble the full base camp temperature report

    Step 5: Assembling the report

    Everything you've built so far is a piece: Readings.java captures values, Conversions.java translates units, Statistics.java summarizes a batch. Report.java is where those pieces become the tool the doctor actually runs — starting with one camp's line of text. ## Rolling camps up into a day

    A single camp's line is useful, but the doctor also wants to know how the whole day looked across every camp at once. That's exactly what Step 4's overloaded average and formatReading were built for — call them here instead of re-deriving averaging or formatting logic a second time. ## The line that matters most

    Everything else in the report is context; the safety flag is the line the doctor actually scans for first thing in the morning. It depends on correctly finding the coldest reading of the day and comparing it against a fixed threshold — get the comparison direction wrong and a dangerous morning reads as SAFE. This final task calls every method you've built across all four files to produce the complete, printed report.

  6. Challenge

    Step 6: Run the application

    Every task is done, and each one was graded the moment you completed it. What you have not done yet is watch the whole application run at once -- which is the only place the pieces you wrote separately become a single working program.

    Start the application

    Open the Terminal tab and run:

    java -cp target/classes lab.Main
    

    If you've made any changes of your own since your last passing check, recompile first:

    mvn --batch-mode -o compile
    java -cp target/classes lab.Main
    

    The program runs in the terminal and prints its output there. Every behaviour it shows is code you wrote in the previous steps, so read the output against what each task asked for -- that is the whole lab, working as one program. ### Run the checks yourself

    The lab ran each task's test for you as you went, but they are ordinary tests and you can run them whenever you like. The whole suite:

    mvn --batch-mode --quiet test
    

    Or one task at a time:

    bash runTest.sh task_2_1
    

    Each failure names the task it belongs to, so the output tells you which step to go back to rather than which line to stare at. Two things worth trying before you finish: break something on purpose and watch the matching check fail, then put it back. Knowing what a failure looks like is worth as much as knowing what a pass looks like, and it costs you nothing here.

    When you are done, everything you wrote is still in the editor tabs -- the lab is yours to keep reading.

About the author

Pluralsight’s AI authoring technology is designed to accelerate the creation of hands-on, technical learning experiences. Serving as a first-pass content generator, it produces structured lab drafts aligned to learning objectives defined by Pluralsight’s Curriculum team. Each lab is then enhanced by our Content team, who configure the environments, refine instructions, and conduct rigorous technical and quality reviews. The result is a collaboration between artificial intelligence and human expertise, where AI supports scale and efficiency, and Pluralsight experts ensure accuracy, relevance, and instructional quality, helping learners build practical skills with confidence.

Real skill practice before real-world application

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Learn by doing

Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.

Follow your guide

All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.

Turn time into mastery

On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.

Get started with Pluralsight