package com.google.step.YOUR_PROJECT_NAME_HERE.external;

import com.google.step.YOUR_PROJECT_NAME_HERE.data.Card;
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

public final class W3SchoolClient {
  private static final String CARD_TITLE_ID = "h1";
  private static final String CARD_DESC_ID = "p";
  private static final String CARD_SNIPPET_ID = "w3-example";
  private static final String CARD_CODE_ID = "w3-code";

  public Card search(String w3Link) throws IOException {

    Document doc = Jsoup.connect(w3Link).get();
    Elements titles = doc.getElementsByTag(CARD_TITLE_ID);
    Elements descriptions = doc.getElementsByTag(CARD_DESC_ID);
    Elements snippets = doc.getElementsByClass(CARD_SNIPPET_ID);

    String title = "";
    String description = "";
    String code = "";

    if (!isNullOrEmpty(titles) && !isNullOrEmpty(descriptions) && !isNullOrEmpty(snippets)) {
      title = titles.first().text();
      description = descriptions.first().text();
      code = snippets.first().getElementsByClass(CARD_CODE_ID).text();
    }

    if (!title.isEmpty() && !description.isEmpty() && !code.isEmpty()) {
      Card w3Card = new Card(title, code, w3Link, description);
      return w3Card;
    }
    return null;
  }

  public boolean isNullOrEmpty(Elements elements) {
    return elements == null || elements.isEmpty();
  }
}

@@ -525,42 +525,44 @@
 nk) 
-throws IOException %7B%0A%0A    Document
+%7B%0A%0A    Document doc;%0A    try %7B%0A     
  doc
@@ -593,24 +593,26 @@
 .get();%0A    
+  
 Elements tit
@@ -650,24 +650,26 @@
 _TITLE_ID);%0A
+  
     Elements
@@ -720,24 +720,26 @@
 SC_ID);%0A    
+  
 Elements sni
@@ -788,16 +788,18 @@
 T_ID);%0A%0A
+  
     Stri
@@ -813,24 +813,26 @@
 e = %22%22;%0A    
+  
 String descr
@@ -840,24 +840,26 @@
 ption = %22%22;%0A
+  
     String c
@@ -877,93 +877,80 @@
     
+  
 if (!
-isNullOrEmpty(titles) && !isNullOrEmpty(descriptions) && !isNullOrEmpty(snippets
+titles.isEmpty() && !descriptions.isEmpty() && !snippets.isEmpty(
 )) %7B
@@ -956,16 +956,18 @@
 %7B%0A      
+ 
+ 
 title = 
@@ -985,24 +985,26 @@
 t().text();%0A
+  
       descri
@@ -1046,16 +1046,18 @@
 ;%0A      
+ 
+ 
 code = s
@@ -1117,19 +1117,22 @@
 ();%0A    
-%7D%0A%0A
+  %7D%0A  
     if (
@@ -1206,21 +1206,16 @@
     
+ 
-Card w3Card =
+ return
  new
@@ -1265,29 +1265,12 @@
     
-return w3Card;
+%7D
 %0A  
-  %7D%0A
     
@@ -1288,67 +1288,40 @@
 ;%0A  
-%7D%0A%0A  public boolean isNullOrEmpty(Elements elements
+  %7D catch (IOException e
 ) %7B%0A    
 retu
@@ -1320,54 +1320,28 @@
     
+ 
+ 
 return 
-elements == null %7C%7C elements.isEmpty();
+null;%0A    %7D
 %0A  %7D

Remove exception throw