Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I made a SimpleGeometricObject class, a Point class that finds the distance between two points, and a TriangleFromSimpleGeometricObject class that is a subclass to find

I made a SimpleGeometricObject class, a Point class that finds the distance between two points, and a TriangleFromSimpleGeometricObject class that is a subclass to find the area and perimeter of a triangle given three points. However, my test program isn't working. I'm getting this response after running it: Exception in thread "main" java.lang.NullPointerException at TriangleFromSimpleGeometricObject.(TriangleFromSimpleGeometricObject.java:42) at TestTriangle.main(TestTriangle.java:18).

Here is Point:

public class Point {

private double x; private double y; public Point () { } public Point(double x, double y) { this.x = x; this.y = y; } public double getX() { return x; } public double getY() { return y; } public double getDistance(Point PointB) { double x2 = PointB.getX(); double y2 = PointB.getY(); double part1 = (x2 - x)*(x2 - x); double part2 = (y2 - y)*(y2 - y); return Math.sqrt((part1) + (part2)); } // Point Point1 = new Point(1,1); // Point Point2 = new Point(0,0); // System.out.println(Point1.getDistance(Point2));

}

Here is TriangleFromSimpleGeometricObject:

public class TriangleFromSimpleGeometricObject extends SimpleGeometricObject { private Point A; private Point B; private Point C; public TriangleFromSimpleGeometricObject() { } public TriangleFromSimpleGeometricObject(Point a, Point b, Point c) { this.A = a; this.B = b; this.C = c; } //* Return point A public Point getA() { return A; } //* Return point B public Point getB() { return B; } //* Return point C public Point getC() { return C; }

//* Get side lengths public double getDistance(Point a, Point b) { } double LengthA = A.getDistance(B); double LengthB = B.getDistance(C); double LengthC = C.getDistance(A); //*getArea public double getArea() { double Semi = (LengthA + LengthB + LengthC)/2; double Area = Math.sqrt((Semi)*(Semi - LengthA)*(Semi - LengthB)*(Semi - LengthC)); return Area; } //*Get Perimeter public double getPerimeter() { double Perimeter = LengthA + LengthB + LengthC; return Perimeter; }

public String toString() { return "The triangle was created on " + getDateCreated() + " with the points " + A + " " + B + " "+ C; } }

Here is TestTriangle:

public class TestTriangle { public static void main(String[] args) { //*(1,3), (-2,-2), (3,-1) double x1 = 1; double y1 = 3; double x2 = -2; double y2 = -2; double x3 = 3; double y3 = -1; Point A = new Point(x1, y1); Point B = new Point(x2, y2); Point C = new Point(x3, y3); TriangleFromSimpleGeometricObject triangle = new TriangleFromSimpleGeometricObject(A, B, C); System.out.println(triangle.toString()); System.out.println("The area is " + triangle.getArea() + "."); System.out.println("The perimeter is " + triangle.getPerimeter() + "."); } }

Thanks!

.

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

Database Processing

Authors: David M. Kroenke

12th Edition International Edition

1292023422, 978-1292023427

More Books

Students also viewed these Databases questions