Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- interface Browsable {
- void brows(String... url);
- }
- interface Callable {
- void makeCall(String... url);
- }
- class Smartphone implements Browsable, Callable {
- private String model;
- public Smartphone(String model) {
- this.setModel(model);
- }
- @Override
- public void brows(String[] url) {
- for (String string : url) {
- boolean isURL = string.matches("^(\\D+)$") ? true : false;
- if (!(isURL) || string.isEmpty() || !(string.contains("http"))) {
- System.out.println("Invalid URL!");
- continue;
- }
- System.out.printf("Browsing: %s!%n", string);
- }
- }
- @Override
- public void makeCall(String[] url) {
- for (String string : url) {
- boolean isNumeric = string.matches("^(\\d+)$") ? true : false;
- if (!isNumeric) {
- System.out.println("Invalid number!");
- continue;
- }
- System.out.printf("Calling... %s%n", string);
- }
- }
- private void setModel(String model) {
- this.model = model;
- }
- }
- public class Main {
- public static void main(String[] args) {
- try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));){
- Smartphone phone = new Smartphone("LG");
- phone.makeCall(reader.readLine().trim().split("\\s+"));
- phone.brows(reader.readLine().split("\\s", Integer.MAX_VALUE));
- } catch (Exception e) {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement