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

So i have this project in Java and I am honestly struggling and confused ... For

ID: 3875996 • Letter: S

Question

So i have this project in Java and I am honestly struggling and confused ...

For this part you will implement a simple class (named Point) representing a point in two-dimensional space. Do this by creating a new file named: Point.java and put all code specified below. This class must support the following operations (including a single constructor).

public Point(double x, double y)

Constructor.

public double getX()

Returns the x-coordinate of this point.

public double getY()

Returns the y-coordinate of this point.

public double getRadius()

Returns the distance from the origin to the point.

public double getAngle()

Returns the angle (in radians) from the x-axis in the in range of -pi to pi.

public Point rotate90()

Returns a newly created Point representing a 90-degree (counterclockwise) rotation of this point about the origin. Consider drawing a picture for a point not on an axis as a guide for how you might implement this operation (hint: there is a solution that does not require any sophisticated computations).

______________________________________________________________________________________________________

This is the Testfile that is mentioned ....

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.Map;

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;

/*
* This test is just to get you started.
*/
@Test
public void testGetX()
{
assertEquals(1.0, new Point(1.0, 2.0).getX(), DELTA);
}

/*
* The tests below here are to verify the basic requirements regarding
* the "design" of your class. These are to remain unchanged.
*/

@Test
public void testImplSpecifics()
throws NoSuchMethodException
{
final List expectedMethodNames = Arrays.asList(
"getX",
"getY",
"getRadius",
"getAngle",
"rotate90"
);

final List expectedMethodReturns = Arrays.asList(
double.class,
double.class,
double.class,
double.class,
Point.class
);

final List expectedMethodParameters = Arrays.asList(
new Class[0],
new Class[0],
new Class[0],
new Class[0],
new Class[0]
);

verifyImplSpecifics(Point.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, Point.class.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 < expectedMethodNames.size(); i++)
{
Method method = clazz.getDeclaredMethod(expectedMethodNames.get(i),
expectedMethodParameters.get(i));
assertEquals(expectedMethodReturns.get(i), method.getReturnType());
}

// verify that fields are final
final List nonFinalFields = Arrays.stream(
clazz.getDeclaredFields())
.filter(f -> !Modifier.isFinal(f.getModifiers()))
.collect(Collectors.toList());

assertEquals("Unexpected non-final fields", 0, nonFinalFields.size());
}
}

Explanation / Answer

Hi,

Please find the Point.java class below:

Let me know if you have any questions on this.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote