---
# System prepended metadata

title: Pembahasan 21-24

---

# Pembahasan 21-24
### Nomor 21
![](https://hackmd.io/_uploads/SJbMX7O8h.png)
BrowserTabs merupakan inner class dari Browser; BrowserTabs subclass dari Browser; BrowserTabs memiliki hubungan composition is-a dengan Browser

### Nomor 22
![](https://hackmd.io/_uploads/rJerQQOU3.png)
```java
// Modify this code:
public class Browser{
    private int numTabs;
    
    public void addTabs(String webAddress){
        BrowserTabs tab = new BrowserTabs(webAddress);
    }
    
    private class BrowserTabs {
        private BrowserTabs(String webAddress){
            numTabs++;
            accessWeb(webAddress);
        }
        private void accessWeb(String webAddress){
            System.out.println("Sedang mengakses halaman " + webAddress);
        }
    }
}

```
### Nomor 23
![](https://hackmd.io/_uploads/S1G5VQd8h.png)
```java
// Modify this code
public class Browsing{
    public static void main(String[] args){
        //TODO
        Browser browser = new Browser();
        browser.addTabs("https://scele.cs.ui.ac.id")
    }
}
```

### Nomor 24
![](https://hackmd.io/_uploads/SJEfrQdLn.png)
![](https://hackmd.io/_uploads/SkxSSQuUn.png)
Implementasikan generic method getLessThan!
```java
public static <E extends Comparable<E>> getLessThan(ArrayList<E> items, E comparedItem) {
    // Lengkapi
    ArrayList<E> newArr = new ArrayList<E>();
    
    for (E it: items) {
        if (it.compareTo(comparedItem) < 0) newArr.add(it);
    }
    
    return newArr;
}
```