Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class InvalidCodeException extends Exception {
- public InvalidCodeException(String s) {
- super(s);
- }
- }
- class PhoneRepository {
- public static String getCountryName(String countryCode) throws InvalidCodeException {
- int code = Integer.parseInt(countryCode);
- if (code >= 90 && code <= 100) {
- return "India";
- } else if (code == 901) {
- return "US";
- } else {
- throw new InvalidCodeException("No country with the given code found");
- }
- }
- }
- class Client {
- public static String getCountry(String countryCode) throws InvalidCodeException {
- if (countryCode.length() > 3 || countryCode.length() < 2) {
- throw new InvalidCodeException("Invalid code detail found");
- } else {
- return PhoneRepository.getCountryName(countryCode);
- }
- }
- }
- public class Source1 {
- public static void main(String[] args) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement