Course map
Stage 1: Foundation
Stage 2: Intermediate
Stage 3: Advanced
Stage 4: DSA in Java
Stage 5: Specialization

Part 02 / Topic 9 of 9

Putting it together: restaurant bill splitter

See examples/08_bill_splitter.java. It combines every tool from this part: typed variables, final constants, Scanner input, the int/double casting rule, and a text block for the receipt — no if, no loop, no method beyond main, just a straight sequence of steps.

double gst = subtotal * GST_RATE;
double tip = subtotal * TIP_RATE;
double total = subtotal + gst + tip;
double perPerson = total / people;

Real transcript (subtotal ₹2,450, 4 people):

Food subtotal (₹): 2450
Number of people: 4
---------------------------
Spice Garden, Pune
---------------------------
Subtotal  : ₹2,450.00
GST (5%)  : ₹122.50
Tip (10%) : ₹245.00
---------------------------
Total     : ₹2,817.50
Per person: ₹704.38 (4 people)
---------------------------

%,.2f in the text block's format string does two things at once: , adds the thousands separator, .2f rounds to 2 decimal places. ₹ is written directly in the source — Java source files are UTF-8 by default on a modern JDK, so Unicode characters just work.

Full program: examples/08_bill_splitter.java.

Done here? The practice set for Part 2 — including the solutions — is on the part page.

Search the guide