Skip to content

Lab · Java Programming (Core to Spring Boot)

Lab: a kirana shop bill

Labbeginner· about 1.5 hours· 4 steps

The brief

Sharma General Store wants its bills worked out by a program, not on a calculator. You install the JDK, then write Bill.java: it prints each item and the subtotal, adds GST, rounds the total to the rupee and works out the change from the cash the customer gives.

Why it matters

Billing is the first program most Indian businesses ever ask a developer for, and every billing bug costs real money. The traps in this lab (joining numbers as text, integer division, casting that cuts off instead of rounding) are the same ones that show up in production bills and in Java interview questions.

Skills you practise

  • java -version and javac
  • int and double variables
  • final constants
  • operators and integer division
  • Math.round
  • Scanner

You need

  • JDK 21 (Eclipse Temurin from adoptium.net or Oracle JDK; JDK 17 or any newer version also works)
  • A text editor or IDE (VS Code with the Extension Pack for Java, or IntelliJ IDEA Community Edition) and a terminal

What you will have at the end

Bill.java that prints a complete kirana bill: items, subtotal, GST, the rounded total and the change, with the output of one run pasted below it.

How it is marked (rubric, 100 points)
Correct amountsEvery check passes: subtotal 711, GST 35.55, total 746.55, payable 747, change 253.45
Right typesints for quantities and prices, a final double for the GST rate, long for the rounded total; no integer-division or cast bugs.25
Readable codeClear camelCase names, the constant in UPPER_SNAKE_CASE, one statement per line.15
Can explain itYou can say why brackets, 5.0 and Math.round were needed.15

0/4 steps done

Step 1 of 4

Check the JDK

java and javac both run in a terminal and are version 17 or newer.

The JDK gives you two programs: javac, the compiler that turns Bill.java into Bill.class (bytecode), and java, which runs it on the JVM. Install JDK 21, then open a NEW terminal so it picks up the changed PATH. java -version prints three lines; javac -version prints one. If either says "not recognized", the JDK's bin folder is not on PATH.

$ java -version
openjdk version "21.0.5" 2024-10-15 LTS
...
$ javac -version
javac 21.0.5
Your exact numbers may differ; 17 or newer is fine.
Run this on your machine, then paste the output below
$ java -version javac -version
Your notes: Bill.java

Write down each command you ran. It goes into your project summary.