Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am having trouble with an android studio proejct. I have one class that lists

ID: 3856960 • Letter: I

Question

I am having trouble with an android studio proejct. I have one class that lists three different groups :

-----------------I have a general "group" class:-------------------

There are two different objectives that I am having trouble figuring out. The first involves creating a "bounding box" or the smallest rectangle that would encompass the group of objects. This is the"bounding box" class that I need to change.

}

I was given a test class that asserts certain things:

}

The other problem was with the "draw" class that atually draws the group of shapes.

Again, I have a test class which is as follows:

I am having toruble figuring out a general way to code for this. Any help would be great.

Explanation / Answer

import static org.mockito.Mockito.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
//TestDraw.java

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;

import edu.luc.etl.cs313.android.shapes.model.Fixtures;
import edu.luc.etl.cs313.android.shapes.model.Visitor;

@RunWith(MockitoJUnitRunner.class)
public class TestDraw {

   @Mock private Canvas canvas;
   @Mock private Paint paint;
   private InOrder inOrder;

   private Visitor<Void> draw;

   @Before
   public void setUp() {
       inOrder = inOrder(canvas, paint);
       draw = new Draw(canvas, paint);
   }

   @After
   public void tearDown() {
       draw = null;
       inOrder = null;
       paint = null;
       canvas = null;
   }

   @Test
   public void testSimpleLocation() {
       Fixtures.simpleLocation.accept(draw);
       inOrder.verify(canvas).translate(70, 30);
       inOrder.verify(canvas).drawRect(0, 0, 80, 120, paint);
       inOrder.verify(canvas).translate(-70, -30);
   }

   @Test
   public void testSimpleGroup() {
       Fixtures.simpleGroup.accept(draw);
       inOrder.verify(canvas).translate(200, 100);
       inOrder.verify(canvas).drawCircle(0, 0, 50, paint);
       inOrder.verify(canvas).translate(-200, -100);
       inOrder.verify(canvas).translate(400, 300);
       inOrder.verify(canvas).drawRect(0, 0, 100, 50, paint);
       inOrder.verify(canvas).translate(-400, -300);
   }

   @Test
   public void testComplexGroup() {
       Fixtures.complexGroup.accept(draw);
       inOrder.verify(canvas).translate(50, 100);
       inOrder.verify(canvas).drawCircle(0, 0, 20, paint);
       inOrder.verify(canvas).drawRect(0, 0, 100, 200, paint);
       inOrder.verify(canvas).translate(150, 50);
       inOrder.verify(paint).setColor(Color.RED);
       inOrder.verify(paint).setStyle(Style.FILL_AND_STROKE);
       inOrder.verify(canvas).drawRect(0, 0, 50, 30, paint);
       inOrder.verify(paint).setStyle(Style.STROKE);
       inOrder.verify(canvas).drawRect(0, 0, 300, 60, paint);
       inOrder.verify(paint).setStyle(any(Style.class));
       inOrder.verify(paint).setColor(Color.CYAN);
       inOrder.verify(canvas).drawLines((float[]) any(), eq(paint));
       inOrder.verify(paint).setColor(anyInt());
       inOrder.verify(canvas).translate(100, 200);
       inOrder.verify(paint).setColor(Color.MAGENTA);
       inOrder.verify(paint).setStyle(Style.STROKE);
       inOrder.verify(canvas).drawCircle(0, 0, 50, paint);
       inOrder.verify(paint).setStyle(any(Style.class));
       inOrder.verify(paint).setColor(anyInt());
       inOrder.verify(canvas).translate(-100, -200);
       inOrder.verify(paint).setStyle(any(Style.class));
       inOrder.verify(paint).setColor(anyInt());
       inOrder.verify(canvas).translate(-150, -50);
       inOrder.verify(canvas).translate(-50, -100);
   }
}

====================================================================

//Fixtures.java

import android.graphics.Color;

/**
* Test fixtures shared across test cases.
*/
public class Fixtures {

   private Fixtures() { /* prevent instantiation! */ }

   public static final Shape simpleLocation = new Location(70, 30, new Rectangle(80, 120));

   public static final Shape simpleFill = new Fill(new Rectangle(80, 120));

   public static final Shape simpleStroke = new Stroke(Color.RED, new Rectangle(80, 120));

   public static final Shape simpleGroup = new Group(
       new Location(200, 100, new Circle(50)),
       new Location(400, 300, new Rectangle(100, 50))
   );

   public static final Shape complexGroup = new Location(50, 100,
       new Group(
           new Circle(20),
           new Rectangle(100, 200),
           new Location(150, 50,
               new Stroke(Color.RED,
                   new Fill(
                       new Group(
                           new Rectangle(50, 30),
                           new Outline(new Rectangle(300, 60)),
                           new Stroke(Color.CYAN,
                               new Polygon(
                                   new Point(50, 50),
                                   new Point(60, 100),
                                   new Point(100, 110),
                                   new Point(120, 60)
                               )
                           ),
                           new Location(100, 200,
                               new Stroke(Color.MAGENTA,
                                   new Outline(new Circle(50))
                               )
                           )
                       )
                   )
               )
           )
       )
   );

   public static final Shape simpleOutline = new Outline(new Rectangle(80, 120));

   public static final Shape simplePolygon = new Polygon(
       new Point(50, 50),
       new Point(60, 100),
       new Point(100, 110),
       new Point(120, 60)
   );
}

===============================================================

// TestBoundingBox.java

import static edu.luc.etl.cs313.android.shapes.model.Fixtures.*;
import static org.junit.Assert.assertEquals;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class TestBoundingBox {

   protected BoundingBox v;

   @Before
   public void setUp() {
       v = new BoundingBox();
   }

   @After
   public void tearDown() {
       v = null;
   }

   @Test
   public void testCircle() {
       final Location b = new Circle(50).accept(v);
       final Rectangle r = (Rectangle) b.getShape();
       assertEquals(-50, b.getX());
       assertEquals(-50, b.getY());
       assertEquals(100, r.getWidth());
       assertEquals(100, r.getHeight());
   }

   @Test
   public void testRectangle() {
       final Location b = new Rectangle(80, 120).accept(v);
       final Rectangle r = (Rectangle) b.getShape();
       assertEquals(0, b.getX());
       assertEquals(0, b.getY());
       assertEquals(80, r.getWidth());
       assertEquals(120, r.getHeight());
   }

   @Test
   public void testLocation() {
       final Location b = simpleLocation.accept(v);
       final Rectangle r = (Rectangle) b.getShape();
       assertEquals(70, b.getX());
       assertEquals(30, b.getY());
       assertEquals(80, r.getWidth());
       assertEquals(120, r.getHeight());
   }

   @Test
   public void testFilled() {
       final Location b = simpleFill.accept(v);
       final Rectangle r = (Rectangle) b.getShape();
       assertEquals(0, b.getX());
       assertEquals(0, b.getY());
       assertEquals(80, r.getWidth());
       assertEquals(120, r.getHeight());
   }

   @Test
   public void testStroke() {
       final Location b = simpleStroke.accept(v);
       final Rectangle r = (Rectangle) b.getShape();
       assertEquals(0, b.getX());
       assertEquals(0, b.getY());
       assertEquals(80, r.getWidth());
       assertEquals(120, r.getHeight());
   }

   @Test
   public void testGroupSimple() {
       Location b = simpleGroup.accept(v);
       Rectangle r = (Rectangle) b.getShape();
       assertEquals(150, b.getX());
       assertEquals(50, b.getY());
       assertEquals(350, r.getWidth());
       assertEquals(300, r.getHeight());
   }

   @Test
   public void testGroupComplex() {
       final Location b = complexGroup.accept(v);
       final Rectangle r = (Rectangle) b.getShape();
       assertEquals(30, b.getX());
       assertEquals(80, b.getY());
       assertEquals(470, r.getWidth());
       assertEquals(320, r.getHeight());
   }

   @Test
   public void testOutline() {
       final Location b = simpleOutline.accept(v);
       final Rectangle r = (Rectangle) b.getShape();
       assertEquals(0, b.getX());
       assertEquals(0, b.getY());
       assertEquals(80, r.getWidth());
       assertEquals(120, r.getHeight());
   }

   @Test
   public void testPolygon() {
       final Location b = simplePolygon.accept(v);
       final Rectangle r = (Rectangle) b.getShape();
       assertEquals(50, b.getX());
       assertEquals(50, b.getY());
       assertEquals(70, r.getWidth());
       assertEquals(60, r.getHeight());
   }
}

=====================================================================

//TestSize.java

import static org.junit.Assert.assertEquals;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static edu.luc.etl.cs313.android.shapes.model.Fixtures.*;

public class TestSize {

   protected Size v;

   @Before
   public void setUp() {
       v = new Size();
   }

   @After
   public void tearDown() {
       v = null;
   }

   @Test
   public void testCircle() {
       assertEquals(1, new Circle(50).accept(v).intValue());
   }

   @Test
   public void testRectangle() {
       assertEquals(1, new Rectangle(80, 120).accept(v).intValue());
   }

   @Test
   public void testLocation() {
       assertEquals(1, simpleLocation.accept(v).intValue());
   }

   @Test
   public void testFill() {
       assertEquals(1, simpleFill.accept(v).intValue());
   }

   @Test
   public void testStroke() {
       assertEquals(1, simpleStroke.accept(v).intValue());
   }

   @Test
   public void testGroupSimple() {
       assertEquals(2, simpleGroup.accept(v).intValue());
   }

   @Test
   public void testGroupComplex() {
       assertEquals(6, complexGroup.accept(v).intValue());
   }

   @Test
   public void testOutline() {
       assertEquals(1, simpleOutline.accept(v).intValue());
   }

   @Test
   public void testPolygon() {
       assertEquals(1, simplePolygon.accept(v).intValue());
   }
}

====================================================================