1. Engineering
  2. Computer Science
  3. so im creating a recursive hstructure in java as an...

Question: so im creating a recursive hstructure in java as an...

Question details

So I'm creating a recursive H-structure in Java as an exercise and can't figure how to print my points after I've declared them and the recursive process.

This is what I have so far:

package exercise18_35;

import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;
import javax.imageio.ImageIO;
import java.util.LinkedList;
import java.util.TreeSet;

/**
*
* @author
*/
public class Exercise18_35 {

    public static void drawH(double x, double y, double size) {
//points
        double x0 = x - size/2;
        double x1 = x + size/2;
        double y0 = y - size/2;
        double y1 = y + size/2;

//Drawing the middle H
         StdDraw.line(x0, y0, x0, y1);    // left vertical segment of the H
         StdDraw.line(x1, y0, x1, y1);    // right vertical segment of the H
         StdDraw.line(x0, y, x1, y);    // crossbar segment of the H
     }

     // plot an order n H-tree, centered on (x, y) of the given side length
     public static void draw(int n, double x, double y, double size) {
         if (n == 0) return;             // base case
         drawH(x, y, size);

         // compute x- and y-coordinates of the 4 half-size H-trees
         double x0 = x - size/2;
         double x1 = x + size/2;
         double y0 = y - size/2;
         double y1 = y + size/2;

         // recursively draw 4 half-size H-trees of order n-1
         draw(n-1, x0, y0, size/2);    // lower left H-tree
         draw(n-1, x0, y1, size/2);    // upper left H-tree
         draw(n-1, x1, y0, size/2);    // lower right H-tree
         draw(n-1, x1, y1, size/2);    // upper right H-tree
     }
// read in a command line argument N and plot an order N H-tree
     public static void main(String[] args, double size) {
         int N = Integer.parseInt(args[0]);

         double x = 0.5, y = 0.5;     // center of H-tree         double size = 0.5;           // side length of H-tree
         draw(N, x, y, size);
       
     }
      
       

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution