Loading
0x80Lesson 9 of 9

Practical lab: order summary report

Combine collections, loops, and validation in a realistic mini-project.

14 min 4-question quiz 1 code exercise
By the end of this lesson you can
  • Build a deterministic summary report from raw order records.

A common Java automation task is turning raw input rows into a grouped report. This lab combines string parsing, maps, loops, and validation into one practical workflow.

Main.java
1String[] rows = {"north,120", "south,80", "north,20"};
2int north = 0;
3int south = 0;
4for (String row : rows) {
5    String[] parts = row.split(",");
6    if (parts[0].equals("north")) north += Integer.parseInt(parts[1]);
7    if (parts[0].equals("south")) south += Integer.parseInt(parts[1]);
8}
9System.out.println("north=" + north + "; south=" + south);
Output
north=140; south=80

This pattern appears in support tooling and batch processing jobs. Deterministic output and explicit validation rules make scripts easier to test and maintain.

Key takeaways

  • Build a deterministic summary report from raw order records.

  • Java checks types as it compiles your source.

  • Use compiler messages as clues about what needs fixing.

Lesson quiz

4 questions · pass with 3 correct · up to 50 XP

Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.

Practice: write Java

Write Java in the editor and run it against sample input with a remote compiler. Your code is sent to Compiler Explorer to compile and run.

Exercise 1

Build a two-region order summary

+25 XP

Read integer n, then n rows formatted region,amount. Valid regions are north and south. Ignore rows with invalid amounts or unknown regions. Print north=<total>; south=<total>.

  • Valid and invalid rows
  • Only south
Main.java
Loading editor…

Java is compiled and run by Compiler Explorer (godbolt.org), a free public service. Your source code and test input are sent to that service.

Questions about this lesson

Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.

Loading posts…