Guest User

Untitled

a guest
Jan 22nd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. import java.awt.Point;
  2.  
  3. public class Geom {
  4.  
  5. public Point A;
  6. public Point B;
  7. public Point C;
  8. double AB = distance(A,B);
  9. double BC = distance(B,C);
  10. double AC = distance(A,C);
  11.  
  12. Geom(Point A,Point B,Point C) {
  13.  
  14. this.A = A;
  15. this.B = B;
  16. this.C = C;
  17.  
  18. }
  19. public static double distance(Point M, Point N) {
  20.  
  21. double dist = Math.sqrt((N.x - M.x)^2+(N.y - M.y)^2);
  22. return dist;
  23.  
  24. }
  25.  
  26. public double triangleSemiPerimeter() {
  27.  
  28. double semi = (AC+AC+BC)/2;
  29. return semi;
  30.  
  31. }
  32. }
  33.  
  34. import java.awt.Point;
  35.  
  36.  
  37. public class Password {
  38.  
  39. public static void main(String[] args) {
  40. Point A = new Point(6,4);
  41. Point B = new Point(10,7);
  42. Point C = new Point(8,3);
  43. Geom myGeom = new Geom(A,B,C);
  44.  
  45. System.out.print(myGeom.triangleSemiPerimeter());
  46.  
  47.  
  48. }
  49.  
  50. }
  51.  
  52.  
  53. run:
  54. Exception in thread "main" java.lang.NullPointerException
  55. at password.Geom.distance(Geom.java:23)
  56. at password.Geom.<init>(Geom.java:10)
  57. at password.Password.main(Password.java:12)
  58. Java Result: 1
  59. BUILD SUCCESSFUL (total time: 0 seconds)
Add Comment
Please, Sign In to add comment