Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Point;
- public class Geom {
- public Point A;
- public Point B;
- public Point C;
- double AB = distance(A,B);
- double BC = distance(B,C);
- double AC = distance(A,C);
- Geom(Point A,Point B,Point C) {
- this.A = A;
- this.B = B;
- this.C = C;
- }
- public static double distance(Point M, Point N) {
- double dist = Math.sqrt((N.x - M.x)^2+(N.y - M.y)^2);
- return dist;
- }
- public double triangleSemiPerimeter() {
- double semi = (AC+AC+BC)/2;
- return semi;
- }
- }
- import java.awt.Point;
- public class Password {
- public static void main(String[] args) {
- Point A = new Point(6,4);
- Point B = new Point(10,7);
- Point C = new Point(8,3);
- Geom myGeom = new Geom(A,B,C);
- System.out.print(myGeom.triangleSemiPerimeter());
- }
- }
- run:
- Exception in thread "main" java.lang.NullPointerException
- at password.Geom.distance(Geom.java:23)
- at password.Geom.<init>(Geom.java:10)
- at password.Password.main(Password.java:12)
- Java Result: 1
- BUILD SUCCESSFUL (total time: 0 seconds)
Add Comment
Please, Sign In to add comment