← Back to Week 2 Hub
Workbook 2a — Exercise 5

Address Builder

Collect name and addresses, then build formatted output with StringBuilder  |  Workbook p.28

What You're Building

Ask the user for their full name, then collect a billing address (street, city, state, zip) and a shipping address (same parts). Use StringBuilder to assemble a nicely formatted multi-line output showing the name with both addresses.

Example Run
Run 1 — Different billing and shipping
Enter your full name: Pat Morgan

Billing street: 123 Main St
Billing city: Dallas
Billing state: TX
Billing zip: 75201

Shipping street: 456 Oak Ave
Shipping city: Austin
Shipping state: TX
Shipping zip: 73301

Name: Pat Morgan

Billing Address:
123 Main St
Dallas, TX 75201

Shipping Address:
456 Oak Ave
Austin, TX 73301
Run 2 — Same billing and shipping
Enter your full name: Sam Lee

Billing street: 789 Elm Blvd
Billing city: Denver
Billing state: CO
Billing zip: 80202

Shipping street: 789 Elm Blvd
Shipping city: Denver
Shipping state: CO
Shipping zip: 80202

Name: Sam Lee

Billing Address:
789 Elm Blvd
Denver, CO 80202

Shipping Address:
789 Elm Blvd
Denver, CO 80202
Concepts You'll Use
Flow Diagram
Get name
Get billing parts
Get shipping parts
Build with StringBuilder
Display

Workbook 2a, p.28 — Exercise 5: Address Builder

← Theater Reservations CellPhone Service →