deyanmalinov

4. Telephony

Jul 10th, 2020
1,209
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package DPM;
  2. import java.util.Scanner;
  3. public class Main {
  4.     public static void main(String[] args){
  5.         Scanner scan = new Scanner(System.in);
  6.         String[] phones = scan.nextLine().split(" ");
  7.         String[] emails = scan.nextLine().split(" ");
  8.         Smartphone note10 = new Smartphone();
  9.         for (String phone : phones) {
  10.             try {
  11.                 System.out.println(note10.call(phone));
  12.             }catch (IllegalArgumentException msg){
  13.                 System.out.println(msg.getMessage());
  14.             }
  15.         }
  16.         for (String mail : emails) {
  17.             try {
  18.                 System.out.println(note10.browse(mail));
  19.             }catch (IllegalArgumentException msg){
  20.                 System.out.println(msg.getMessage());
  21.             }
  22.         }
  23.     }
  24. }------------------------------------
  25. package DPM;
  26. public interface Browsable {
  27.     String browse(String site);
  28. }----------------------------------
  29. package DPM;
  30. public interface Callable {
  31.     String call(String number);
  32. }--------------------------------
  33. package DPM;
  34. public class Smartphone implements Browsable, Callable{
  35.     public Smartphone(){
  36.     }
  37.     @Override
  38.     public String browse(String site) {
  39.         if (site.matches(".*\\d+.*")){
  40.             throw new IllegalArgumentException("Invalid URL!");
  41.         }
  42.         return String.format("Browsing: %s!", site);
  43.     }
  44.     @Override
  45.     public String call(String num) {
  46.         if (!num.matches("\\d+")){
  47.             throw new IllegalArgumentException("Invalid number!");
  48.         }
  49.         return String.format("Calling... %s", num);
  50.     }
  51. }
RAW Paste Data