public class CellPhone extends Object
Every cell phone has a call log. The cell phone and its call log form a composition. A call log is a list of cell numbers that have been called using this cell phone. The order of contacts in the call log are from the oldest call to the most recent call.
Constructor and Description |
---|
CellPhone()
Initializes this cell phone to have a valid cell number.
|
CellPhone(CellNumber number)
Initializes this cell phone given its cell number.
|
CellPhone(CellNumber number,
List<CellNumber> callLog)
Initializes this cell phone given a cell number and a call log.
|
Modifier and Type | Method and Description |
---|---|
void |
dial(CellNumber number)
Dial a cell number using this phone.
|
CellNumber |
favorite()
Returns the favorite cell number that has been called using this cell phone.
|
List<CellNumber> |
getCallLog()
Returns a shallow copy of call log for this phone.
|
CellNumber |
getNumber()
Returns a new copy of the cell number for this phone.
|
void |
setNumber(CellNumber number)
Sets the cell number of this phone to a new copy of the
given cell number.
|
String |
toString()
Returns a string representation of this cell phone.
|
public CellPhone()
public CellPhone(CellNumber number)
number
- the cell number for this phonepublic CellPhone(CellNumber number, List<CellNumber> callLog)
number
- the number for this phonecallLog
- the call log for this phonepublic CellNumber getNumber()
public void setNumber(CellNumber number)
number
- the new cell number for this phonepublic List<CellNumber> getCallLog()
public CellNumber favorite()
Returns null if this cell phone has never dialed a cell number.
Hint: Use Collections.frequency to count the number of times each cell number appears in the call log, or use a Map.
public void dial(CellNumber number)
number
- a cell number to dialIllegalArgumentException
- if number == null