Loading...
Loading...
Loading...
A college prints one line per student. A student may have an address (a city and a PIN code) or none yet.
Write Address with private city and pin, and Student with a private name and a private Address part. Student.describe() returns the line, and handles a missing address itself.
- means the student has no address yet.NAME lives in CITY - PIN, or NAME has no address.Example
Input
3 Aarav Pune 411001 Ravi - 0 Diya Chennai 600001
Output
Aarav lives in Pune - 411001 Ravi has no address Diya lives in Chennai - 600001
Ravi has no address, so his address field stays null.
Try the problem first. Open one hint at a time.
Create the Address only when the city is not -; otherwise pass null.
Put the null check inside Student.describe(), so callers never touch the address directly.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor