Consider this code:

class BstNode:

    def __init__(self, key):
        self.key = key
        self.right = None
        self.left = None

    def insert(self, key):
        if self.key == key:
            return
        elif self.key < key:
            if self.right is None:
                self.right = BstNode(key)
            else:
                self.right.insert(key)
        else: # self.key > key
            if self.left is None:
                self.left = BstNode(key)
            else:
                self.left.insert(key)

    def display(self):
        lines, *_ = self._display_aux()
        for line in lines:
            print(line)

    def _display_aux(self):
        """Returns list of strings, width, height, and horizontal coordinate of the root."""
        # No child.
        if self.right is None and self.left is None:
            line = '%s' % self.key
            width = len(line)
            height = 1
            middle = width // 2
            return [line], width, height, middle

        # Only left child.
        if self.right is None:
            lines, n, p, x = self.left._display_aux()
            s = '%s' % self.key
            u = len(s)
            first_line = (x + 1) * ' ' + (n - x - 1) * '_' + s
            second_line = x * ' ' + '/' + (n - x - 1 + u) * ' '
            shifted_lines = [line + u * ' ' for line in lines]
            return [first_line, second_line] + shifted_lines, n + u, p + 2, n + u // 2

        # Only right child.
        if self.left is None:
            lines, n, p, x = self.right._display_aux()
            s = '%s' % self.key
            u = len(s)
            first_line = s + x * '_' + (n - x) * ' '
            second_line = (u + x) * ' ' + '\\' + (n - x - 1) * ' '
            shifted_lines = [u * ' ' + line for line in lines]
            return [first_line, second_line] + shifted_lines, n + u, p + 2, u // 2

        # Two children.
        left, n, p, x = self.left._display_aux()
        right, m, q, y = self.right._display_aux()
        s = '%s' % self.key
        u = len(s)
        first_line = (x + 1) * ' ' + (n - x - 1) * '_' + s + y * '_' + (m - y) * ' '
        second_line = x * ' ' + '/' + (n - x - 1 + u + y) * ' ' + '\\' + (m - y - 1) * ' '
        if p < q:
            left += [n * ' '] * (q - p)
        elif q < p:
            right += [m * ' '] * (p - q)
        zipped_lines = zip(left, right)
        lines = [first_line, second_line] + [a + u * ' ' + b for a, b in zipped_lines]
        return lines, n + m + u, max(p, q) + 2, n + u // 2


import random

b = BstNode(50)
for _ in range(50):
    b.insert(random.randint(0, 100))
b.display()

Now run it: 

====== RESTART: C:/Users/dgerman/Desktop/lab-thu-02-11/pretty-printing.py ======
                      ______________50_____________________________________ 
                     /                                                     \
        ____________37___                           ______________________95
       /                 \                         /                        
 _____14___             41_______       __________65_______                 
/          \           /         \     /                   \                
2____     18_____     38    ____48_   51___           ____79_               
     \   /       \         /       \       \         /       \              
    13  16      32_       42_     49      53___     69_     83___           
   /           /   \         \           /     \       \         \          
  12          27  36        44_         52    62_     74_       85___       
 /           /                 \             /   \       \     /     \      
 7          24                45            54  63      76    84    88_     
                                                                   /   \    
                                                                  86  89_   
                                                                         \  
                                                                        93  
>>> 
====== RESTART: C:/Users/dgerman/Desktop/lab-thu-02-11/pretty-printing.py ======
                             ____50_______                             
                            /             \                            
       ____________________38___       __56_                           
      /                         \     /     \                          
   __13_________               49    52_   58_________________________ 
  /             \             /     /   \                             \
 _9_       ____24_____       48    51  53                      ______97
/   \     /           \                                       /        
4  12    20_         34___                       ____________87___     
 \      /   \       /     \                     /                 \    
 8     18  21_     28    36                    63___________     92_   
              \   /     /                     /             \   /   \  
             22  26    35                    61          __86  88  94  
                                                        /              
                                                     __83_             
                                                    /     \            
                                                   71_   85            
                                                  /   \                
                                                 70  77                
>>> 
====== RESTART: C:/Users/dgerman/Desktop/lab-thu-02-11/pretty-printing.py ======
    _________________________________________50_________________________________  
   /                                                                            \ 
   6__________                                                       __________100
  /           \                                                     /             
  4    ______22_______________________               ______________87___          
 /    /                               \             /                   \         
 3   10___               ____________45_____       56_________         90_        
/   /     \             /                   \     /           \       /   \       
2   8    15_       ____33___________       49    55        __73_     89  92___    
        /   \     /                 \     /     /         /     \             \   
       11  21    25_             __44    47    52      __69_   74_           96   
                /   \           /       /             /     \     \         /     
               23  29_         42_     46            57_   71    86        94     
                      \       /   \                     \                         
                     32    __40  43                    65                         
                          /                                                       
                         38_                                                      
                            \                                                     
                           39                                                     
>>> 

What does it do? 

Your task is to rewrite this in Java based on the info in the C212 textbook. 

We're not just interested in code that works. 

We're interested in stages of development that

(a) clearly demonstrate your understanding, at each step, 
(b) that you could used to teach others (if you were a TA) 

Sincerely,
Adrian German

Last modified: Thu Jun 17 13:43:21 EDT 2021

--