Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hey All I have this Java HW that i would need help with.. I have posted the instructions below and the testcases at the bottom...

Hey All I have this Java HW that i would need help with.. I have posted the instructions below and the testcases at the bottom...

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

TEST CASES

import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.Arrays; import java.util.List; import java.util.ArrayList; import java.util.LinkedList; import java.awt.Color; import java.awt.Point; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import org.junit.Test; public class TestCases { public static final double DELTA = 0.00001; /* some sample tests but you must write more! see lab write up */ @Test public void testCircleGetArea() { Circle c = new Circle(5.678, new Point(2, 3), Color.BLACK); assertEquals(101.2839543, c.getArea(), DELTA); } @Test public void testCircleGetPerimeter() { Circle c = new Circle(5.678, new Point(2, 3), Color.BLACK); assertEquals(35.6759261, c.getPerimeter(), DELTA); } @Test public void testWorkSpaceAreaOfAllShapes() { WorkSpace ws = new WorkSpace(); ws.add(new Rectangle(1.234, 5.678, new Point(2, 3), Color.BLACK)); ws.add(new Circle(5.678, new Point(2, 3), Color.BLACK)); ws.add(new Triangle(new Point(0,0), new Point(2,-4), new Point(3, 0), Color.BLACK)); assertEquals(114.2906063, ws.getAreaOfAllShapes(), DELTA); } @Test public void testWorkSpaceGetCircles() { WorkSpace ws = new WorkSpace(); List expected = new LinkedList(); // Have to make sure the same objects go into the WorkSpace as // into the expected List since we haven't overriden equals in Circle. Circle c1 = new Circle(5.678, new Point(2, 3), Color.BLACK); Circle c2 = new Circle(1.11, new Point(-5, -3), Color.RED); ws.add(new Rectangle(1.234, 5.678, new Point(2, 3), Color.BLACK)); ws.add(c1); ws.add(new Triangle(new Point(0,0), new Point(2,-4), new Point(3, 0), Color.BLACK)); ws.add(c2); expected.add(c1); expected.add(c2); // Doesn't matter if the "type" of lists are different (e.g Linked vs // Array). List equals only looks at the objects in the List. assertEquals(expected, ws.getCircles()); } /* HINT - comment out implementation tests for the classes that you have not * yet implemented */ @Test public void testCircleImplSpecifics() throws NoSuchMethodException { final List expectedMethodNames = Arrays.asList( "getColor", "setColor", "getArea", "getPerimeter", "translate", "getRadius", "setRadius", "getCenter", "equals"); final List expectedMethodReturns = Arrays.asList( Color.class, void.class, double.class, double.class, void.class, double.class, void.class, Point.class, boolean.class); final List expectedMethodParameters = Arrays.asList( new Class[0], new Class[] {Color.class}, new Class[0], new Class[0], new Class[] {Point.class}, new Class[0], new Class[] {double.class}, new Class[0], new Class[] {Object.class}); verifyImplSpecifics(Circle.class, expectedMethodNames, expectedMethodReturns, expectedMethodParameters); } @Test public void testRectangleImplSpecifics() throws NoSuchMethodException { final List expectedMethodNames = Arrays.asList( "getColor", "setColor", "getArea", "getPerimeter", "translate", "getWidth", "setWidth", "getHeight", "setHeight", "getTopLeft", "equals"); final List expectedMethodReturns = Arrays.asList( Color.class, void.class, double.class, double.class, void.class, double.class, void.class, double.class, void.class, Point.class, boolean.class); final List expectedMethodParameters = Arrays.asList( new Class[0], new Class[] {Color.class}, new Class[0], new Class[0], new Class[] {Point.class}, new Class[0], new Class[] {double.class}, new Class[0], new Class[] {double.class}, new Class[0], new Class[] {Object.class}); verifyImplSpecifics(Rectangle.class, expectedMethodNames, expectedMethodReturns, expectedMethodParameters); } @Test public void testTriangleImplSpecifics() throws NoSuchMethodException { final List expectedMethodNames = Arrays.asList( "getColor", "setColor", "getArea", "getPerimeter", "translate", "getVertexA", "getVertexB", "getVertexC", "equals"); final List expectedMethodReturns = Arrays.asList( Color.class, void.class, double.class, double.class, void.class, Point.class, Point.class, Point.class, boolean.class); final List expectedMethodParameters = Arrays.asList( new Class[0], new Class[] {Color.class}, new Class[0], new Class[0], new Class[] {Point.class}, new Class[0], new Class[0], new Class[0], new Class[] {Object.class}); verifyImplSpecifics(Triangle.class, expectedMethodNames, expectedMethodReturns, expectedMethodParameters); } private static void verifyImplSpecifics( final Class> clazz, final List expectedMethodNames, final List expectedMethodReturns, final List expectedMethodParameters) throws NoSuchMethodException { assertEquals("Unexpected number of public fields", 0, clazz.getFields().length); final List publicMethods = Arrays.stream( clazz.getDeclaredMethods()) .filter(m -> Modifier.isPublic(m.getModifiers())) .collect(Collectors.toList()); assertEquals("Unexpected number of public methods", expectedMethodNames.size(), publicMethods.size()); assertTrue("Invalid test configuration", expectedMethodNames.size() == expectedMethodReturns.size()); assertTrue("Invalid test configuration", expectedMethodNames.size() == expectedMethodParameters.size()); for (int i = 0; i   Orientation For this lab you will create a virtual drawing workspace on which you can place various geometric shapes. You will not actually be drawing the shapes in this program, rather, you will simply be representing geometric shapes as objects and providing the ability to place them in space. The workspace will make use of a List from the Java Standard Library to collect shapes and will have methods that allow you to add, remove, and inspect the shapes it contains. All of the shapes share a common set of methods defined by a Java interface. The behavior of these common methods varies as appropriate, by shape. In addition, each shape has one or more methods unique to it. The following shapes will be supported: circle, rectangle, and triangle Objectives . To develop and demonstrate basic object-oriented development skills. Much of the structure of the solution is given use good judgment when "filling in the blanks". . To become familiar with Java interfaces and the concept of polymorphism . To practice using the instanceof operator More practice using existing classes and interfaces from the Java Standard Library, such as List, ArrayList, LinkedList, Point, and color Given Files Retrieve the provided test file for this The given file is a starter junit test file for your code. Be sure to add to this file to make sure your code is working properly. Your instructors have a much more extensive test file that they will test your implementation with! Ground Rules Many of the classes and interfaces you will be writing in this lab have counterparts in the Java Standard Library. You may not use the Java Standard Library versions in your implementation unless explicitly instructed to do so (see below). The Java Standard Library classes and interfaces you may use are identified by a complete package specification. For example, you will be using the java.awt.Color, java.awt. Point, and java.util.List classes/interfaces from the Java Standard Library. You may also use the java.lang.Math class from the Java Standard Library (even though it is not explicitly referenced in this document). Any classes or interfaces in the specifications below (other than Point, Color, and List) must be entirely written by you. If you have any questions regarding this restriction please be sure to ask your instructor early in the development process (ideally, before you of 4 2/3/2018, 10:24 PM

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part I Lnai 8724

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448475, 978-3662448472

More Books

Students also viewed these Databases questions