Skip to content

Instantly share code, notes, and snippets.

@djiwandou
Created October 11, 2019 07:48
Show Gist options
  • Select an option

  • Save djiwandou/8f78bd2cc5cf52359cb146bf8936fd29 to your computer and use it in GitHub Desktop.

Select an option

Save djiwandou/8f78bd2cc5cf52359cb146bf8936fd29 to your computer and use it in GitHub Desktop.
public class Phone {
private final String unformattedNumber;
public Phone(String unformattedNumber) {
this.unformattedNumber = unformattedNumber;
}
public String getAreaCode() {
return unformattedNumber.substring(0,3);
}
public String getPrefix() {
return unformattedNumber.substring(3,6);
}
public String getNumber() {
return unformattedNumber.substring(6,10);
}
}
public class Customer {
private Phone mobilePhone;
public String getMobilePhoneNumber() {
return "(" +
mobilePhone.getAreaCode() + ") " +
mobilePhone.getPrefix() + "-" +
mobilePhone.getNumber();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment