- Lab
-
Libraries: If you want this lab, consider one of these libraries.
- Core Tech
Direct C# Execution with Branches and Methods
A manufacturing shift technician needs a console tool, PulseCheck, to check machine sensor readings (temperature and vibration) against safe operating ranges during a shift. The technician types readings and commands into the console one at a time; the tool must classify each reading as Safe, Warning, or Critical, keep running until the technician types a quit command, and print a final shift report summarizing how many readings were processed and how many fell into each category. You will build this tool piece by piece: first the range checks, then the parsing and branching that classifies a single reading, then the loop that drives the repeating menu and the shared method that removes duplicated threshold code, and finally the session runner that ties everything together into one reported result.
Lab Info
Table of Contents
-
Challenge
Step 1: Meet the PulseCheck shift-log console
Meet PulseCheck
At the start of every shift, a plant-floor technician sits down at a terminal and starts typing sensor readings: temperature in degrees Fahrenheit, vibration in millimeters per second. PulseCheck's job is to look at each number the instant it arrives, decide whether the machine is Safe, drifting into a Warning zone, or already Critical, and keep doing that for every reading the technician enters until they type
quitto log off. When the shift ends, PulseCheck prints one report line summarizing how many readings came in and how bad the worst one was.You are building that tool from the ground up, one method at a time, over the next four steps. ## What you'll build
- Step 2 - boolean helper methods that use relational operators (
<,>,<=,>=) and logical operators (&&,||) to decide whether a single reading, or a temperature-and-vibration pair, falls inside safe bounds. - Step 3 - a parser that turns raw console text into a
doublewithdouble.TryParse, plus bracedif/elsechains that classify a reading as Safe, Warning, or Critical. - Step 4 - a shared method that removes the threshold logic you wrote twice in Step 3, and a
whileloop with counter variables that keeps processing queued commands until it seesquit. - Step 5 - a session runner that ties every piece together, returns a value on every code path (including bad input), and builds the final report with string interpolation. ## How you'll work
Each step hands you a starter file under
src/with the surrounding structure already in place and a// TODO: Task X.Ycomment marking exactly which method body you need to finish. You'll edit only that method, then rundotnet test tests/Lab.Tests.csprojto check your work - a failing test names the behavior that's still missing, not a syntax error to hunt for. By the end of Step 5 you'll have a single console workflow that a technician could genuinely run shift after shift.If you get stuck, you can refer to the provided solution code for each task, available in the
solutionfolder.info> This lab experience was developed by the Pluralsight team using an internally developed AI tool. All sections were verified by human experts for accuracy prior to publications. However, content may still contain errors or inaccuracies, and we recommend independent verification.
To report a problem or provide feedback, click here. Feedback may be used to improve accuracy in accordance with our Privacy Policy. - Step 2 - boolean helper methods that use relational operators (
-
Challenge
Step 2: Build the foundational safe-range checks
Relational operators define a safe band
A reading is "safe" when it sits between a lower and an upper bound - exactly the job of relational operators.
temperatureF >= 60asks whether a value clears the floor;temperatureF <= 90asks whether it stays under the ceiling. Neither comparison alone tells you the whole story, but together they describe a band, and PulseCheck's very first job is turning that band into a boolean your later branching logic can rely on. ## Logical operators combine two conditions into one verdictA machine isn't safe just because its temperature is fine - vibration has to be in range too, at the same time. That's what
&&is for: it only reportstruewhen both sides aretrue. You already have a method that answers the temperature question; the combined check should call it rather than re-deriving the same comparison, and then&&the result with a second range check for vibration. -
Challenge
Step 3: Parse and branch on technician input
Turning console text into numbers
Everything the technician types arrives as a
string, but a range check needs adouble.double.TryParseis built for exactly this handoff: it attempts the conversion, hands the parsed number back through anoutparameter, and returns abooltelling you whether the attempt worked. Checking thatboolbefore trusting the number is what keeps a stray typo like"72..5"from silently becoming0and slipping past every downstream check. ## Branching a number into a categoryWith a trustworthy
doublein hand, the next job is sorting it into one of three labels. A bracedif/elsechain tests conditions top to bottom and runs the first block whose condition istrue, so ordering matters: check the most severe case first, or a Critical reading might get caught by a looser Warning check before it ever reaches the branch that should have handled it. ## The same shape, a second threshold setVibration needs the identical three-tier treatment - Critical, Warning, Safe - just with its own numbers and, notice, only an upper-bound Warning check instead of temperature's two-sided one. Write it now the direct way, even though the two methods will end up sharing a lot of structure; you'll deal with that duplication head-on in the next step.
-
Challenge
Step 4: Drive the shift menu with a counting loop and a shared method
Extracting the repeated logic
Look back at
ClassifyTemperatureandClassifyVibration: both run the same Critical/Warning/Safeif/elseshape, just against different numbers. That's a signal to extract a method - write the comparison logic once, against generic parameters, and have both classifiers call it with their own thresholds. A typed parameter list like(double value, double criticalLow, double warningLow, double warningHigh, double criticalHigh)lets one method serve both callers without either one losing its own bounds. ## Looping until the technician logs offA real shift doesn't process one reading and stop - it keeps going until the technician types
quit. Awhileloop paired with a counter variable is the standard shape for that: initialize an index before the loop, test it (and the current command) in the loop's condition, and increment it on every pass so the loop eventually terminates instead of running forever. ## Counting more than one thing at onceKnowing how many readings came in isn't enough - the shift report needs to know how many were Safe versus Warning versus Critical versus unparsable. The loop shape doesn't change; you just add more counter variables and increment the right one each pass, based on what parsing and classifying that command's text produces.
-
Challenge
Step 5: Assemble the full diagnostics session
Ranking outcomes, not just counting them
A shift with one Critical reading and ten Safe ones is a Critical shift, full stop - the counts alone don't say that, but a priority
if/elsechain does. Test the most severe count first (> 0), return immediately if it's true, and only fall through to lower-severity checks when the more serious ones are all zero. ## Building the report lineString interpolation is what turns five separate numbers and a status string into one readable sentence. Every
{expression}inside a$"..."string gets evaluated and dropped into place, so the report method's whole job is arranging parameters inside one interpolated string and returning it - no concatenation, no hardcoded numbers. ## Returning a value on every pathThe session runner is the one place all four earlier pieces meet: the tally loop, the priority check, and the report formatter. It also has to handle a shift with zero commands, which means it needs more than one
returnstatement - an early return for the empty case, and a final return built from the other three methods' results for every other case. A method with branching logic still returns exactly once per call, but whichreturnstatement executes depends on the path taken. -
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:
dotnet run --project src/Lab.csprojThe 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:
dotnet test tests/Lab.Tests.csproj --nologo --verbosity quietOr one task at a time:
bash runTest.sh Task_2_1Each 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
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.