← Back to Week 2 Hub
CellPhone Service
Create a CellPhone class and build your first object from it
Workbook 2a, p.38-39 — Exercise 1
What You're Building
Create a CellPhone class that represents a cell phone. The class should have five
properties: serial number, model, carrier, phone number, and owner. Include a no-argument
constructor that sets all fields to default values. Add getter and setter methods for each field.
Then in your main class, create one CellPhone object, ask the user for each piece
of information, set the values, and display all the phone's details.
Example Run
Run 1
Enter the serial number: 12345
Enter the model: iPhone 15
Enter the carrier: Verizon
Enter the phone number: 555-123-4567
Enter the owner's name: Dana
Serial Number: 12345
Model: iPhone 15
Carrier: Verizon
Phone Number: 555-123-4567
Owner: Dana
Run 2
Enter the serial number: 98765
Enter the model: Galaxy S24
Enter the carrier: T-Mobile
Enter the phone number: 855-555-2222
Enter the owner's name: Marcus
Serial Number: 98765
Model: Galaxy S24
Carrier: T-Mobile
Phone Number: 855-555-2222
Owner: Marcus
Key detail: You need two files for this exercise — one for the CellPhone class and one for the main application that creates and uses the object.
Concepts You'll Use
This exercise reinforces these concepts from Week 2:
Flow Diagram
Step 1
Create CellPhone class
5 private fields
→
Step 2
Add constructor
No-arg with defaults
→
Step 3
Add getters & setters
For all 5 fields
Step 4
In main: create object
new CellPhone()
→
Step 5
Prompt user for info
Scanner for all 5 fields
→
Step 6
Display phone details
All 5 properties
Think about which data type each field should be. Should serial number be a number or a String?