0 Replies - 376 Views - Last Post: 03 November 2017 - 01:58 PM Rate Topic: -----

#1 Melanie.Snow  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 03-November 17

MBR Intro to Java Assignment help

Posted 03 November 2017 - 01:58 PM

Hello,
I am having a great deal of struggle AND have spent WAAY to much time trying to figure out my JAVA homework, wondering if anyone can help? I am in a beginners Java course.
The premise is we are supposed to use a 1D array to store a MBR or a 2D Box.
We are supposed to write several methods that are going to test if the vertices of certain segments are inside, outside, touches, crosses, or coveredby.
Our output is in a different class, and everything in that section is fine.
My issues stand with the section below:
1) My Output file will only shows INSIDE when it is supposed to show one of each of the enums except unknown
2) My “areXYCoordsInside” code is supposed to call on the two previous methods. The code I have works but that is not what the assignment outlines and I have no idea how to word it.
3) My code for OutsideorTouch does not give any results
4) I am supposed to add logic to the SpatialRelationships method at the end that if all the previous methods fail, then the answer is CROSSES. I again don’t know how to do this.
I’m hoping someone can help steer me in the right direction even somewhat as I am completely lost.

public class GeomFX {
    public static enum SpatialRelationships {
        DISJOINT, TOUCH, CROSS, COVEREDBY, INSIDE, UNKNOWN
    }
    
    ;
    public final static int XMIN = 0;
    public final static int YMIN = 1;
    public final static int XMAX = 2;
    public final static int YMAX = 3;
    public static double[] setBox2D(double xmin, double ymin, double xmax,
                                    double ymax) {
        double[] box = new double[4];

        box[XMIN] = xmin;
        box[XMAX] = xmax;
        box[YMIN] = ymin;
        box[YMAX] = ymax;

        return box;
    }


 
    public static SpatialRelationships spatialRelationship(double[] box2D,
                                                           double[] allXCoords, double[] allYCoords) {
        SpatialRelationships spatilRel = SpatialRelationships.UNKNOWN;
        if (areAllXYCoordsInside (box2D, allXCoords, allYCoords)) {
            spatilRel = SpatialRelationships.INSIDE;
            return spatilRel;
        }
         else if (areAllXYCoordsOutside(box2D, allXCoords, allYCoords))
        {
            spatilRel = SpatialRelationships.DISJOINT;
            return spatilRel;
        }
        else if (areAllXYCoordsInsideOrTouch (box2D, allXCoords, allYCoords)  )
        {
            spatilRel = SpatialRelationships.TOUCH;
            return spatilRel;
        }
        else if (areAllXYCoordsOutsideorTouch (box2D, allXCoords, allYCoords) )
        {
            spatilRel = SpatialRelationships.COVEREDBY;
            return spatilRel;
        }
        return spatilRel;


    }

    public static boolean areAllXCoordsInside(double[] d, double[] box2D, double[] allXCoords) {
        boolean inside = true;

   
        for (int i = 0; i < allXCoords.length; i++) {
            if (allXCoords[i] >= box2D[XMAX]) {
                inside = false;
            }
            if (allXCoords[i] <= box2D[XMIN]) {
                inside = false;
            }
        }
        return inside;
    }


   
    public static boolean areAllYCoordsInside(double[] box2D, double[] allYCoords, double[] yCoords) {
        boolean inside = true;


        for (int i = 0; i < allYCoords.length; i++) {
            if (allYCoords[i] >= box2D[YMAX]) {
                inside = false;
            }
            if (allYCoords[i] <= box2D[YMIN]) {
                inside = false;
            }
        }
        return inside;
    }

    public static boolean areAllXYCoordsInside(double[] box2D,
                                               double[] allXCoords, double[] allYCoords) {
        boolean inside = true;
        for (int i = 0; i < allXCoords.length; i++) {
            if (allXCoords[i] <= box2D[XMIN] && allXCoords[i] >= box2D[XMAX]
                    && allYCoords[i] <= box2D[YMIN]
                    && allYCoords[i] >= box2D[YMAX]) {

                inside = false;
            }
        }
     return inside;
}
   
    public static boolean areAllXYCoordsOutside(double[] box2D,
                                                double[] allXCoords, double[] allYCoords) {
        boolean outside = true;

        for (int i = 0; i < allXCoords.length; i++) {
            if (allXCoords[i] >= box2D[XMIN] && allXCoords[i] <= box2D[XMAX]
                    && allYCoords[i] >= box2D[YMIN]
                    && allYCoords[i] <= box2D[YMAX]) {
                outside = false;
            }

        }

        return outside;
    }

    public static boolean areAllXYCoordsInsideorTouch (double[] box2D,
                                               double[] allXCoords, double[] allYCoords) {
        boolean outside = true;
        for (int i = 0; i < allXCoords.length; i++) {
            if (allXCoords[i] > box2D[XMIN] && allXCoords[i] < box2D[XMAX]
                    && allYCoords[i] > box2D[YMIN]
                    && allYCoords[i] < box2D[YMAX])
            {
                outside = false;
            }
        }
        return outside;
    }
    
    public static boolean areAllXYCoordsOutsideorTouch (double[] box2D,
                                               double[] allXCoords, double[] allYCoords) {
        boolean touch = true;



        for (int i = 0; i < allXCoords.length; i++) {
            if (allXCoords[i] < box2D[XMIN] || allXCoords[i] > box2D[XMAX]
                    || allYCoords[i] > box2D[YMIN]
                    || allYCoords[i] < box2D[YMAX]
                    && allXCoords[i] != box2D[XMIN]
                    && allYCoords[i] != box2D[YMIN])

            {
                touch = false;
            }

        }

        return touch;
    }



}






Is This A Good Question/Topic? 0
  • +

Page 1 of 1