Advertisement
238025681

Telephony

Jul 13th, 2016
640
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.73 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.InputStreamReader;
  3.  
  4.  interface Browsable {
  5.    
  6.     void brows(String... url);
  7. }
  8.  
  9.  interface Callable {
  10.  
  11.     void makeCall(String... url);
  12.  
  13. }
  14.  
  15.  
  16.  class Smartphone implements Browsable, Callable {
  17.     private String model;
  18.  
  19.     public Smartphone(String model) {
  20.         this.setModel(model);
  21.     }
  22.  
  23.  
  24.     @Override
  25.     public void brows(String[] url) {
  26.  
  27.         for (String string : url) {
  28.             boolean isURL = string.matches("^(\\D+)$") ? true : false;
  29.  
  30.             if (!(isURL) || string.isEmpty() || !(string.contains("http"))) {
  31.                 System.out.println("Invalid URL!");
  32.                 continue;
  33.             }
  34.  
  35.             System.out.printf("Browsing: %s!%n", string);
  36.         }
  37.  
  38.     }
  39.  
  40.     @Override
  41.     public void makeCall(String[] url) {
  42.         for (String string : url) {
  43.             boolean isNumeric = string.matches("^(\\d+)$") ? true : false;
  44.            
  45.             if (!isNumeric) {
  46.                 System.out.println("Invalid number!");
  47.                 continue;
  48.                
  49.             }
  50.            
  51.             System.out.printf("Calling... %s%n", string);
  52.         }
  53.     }
  54.  
  55.    
  56.     private void setModel(String model) {
  57.         this.model = model;
  58.     }
  59.    
  60.    
  61. }
  62.  
  63.  
  64.  
  65.  
  66. public class Main {
  67.     public static void main(String[] args) {
  68.         try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));){
  69.             Smartphone phone = new Smartphone("LG");
  70.            
  71.             phone.makeCall(reader.readLine().trim().split("\\s+"));
  72.             phone.brows(reader.readLine().split("\\s", Integer.MAX_VALUE));
  73.            
  74.         } catch (Exception e) {
  75.         }
  76.     }
  77.    
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement