Advertisement
k4u5h4L

Untitled

Apr 11th, 2022
971
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1.  
  2. class InvalidCodeException extends Exception {
  3.   public InvalidCodeException(String s) {
  4.     super(s);
  5.   }
  6. }
  7.  
  8. class PhoneRepository {
  9.   public static String getCountryName(String countryCode) throws InvalidCodeException {
  10.     int code  = Integer.parseInt(countryCode);
  11.    
  12.     if (code >= 90 && code <= 100) {
  13.       return "India";
  14.     } else  if (code == 901) {
  15.       return "US";
  16.     } else {
  17.       throw new InvalidCodeException("No country with the given code found");
  18.     }
  19.   }
  20. }
  21.  
  22. class Client {
  23.   public static String getCountry(String countryCode) throws InvalidCodeException {
  24.     if (countryCode.length() > 3 || countryCode.length() < 2) {
  25.       throw new InvalidCodeException("Invalid code detail found");
  26.     } else {
  27.       return PhoneRepository.getCountryName(countryCode);
  28.     }
  29.   }
  30. }
  31.  
  32. public class Source1 {
  33.  
  34.   public static void main(String[] args) {
  35.    
  36.   }
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement