Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Math;
  3. public class Q5_4
  4. {
  5.  
  6. private static final int NUM = 3;
  7.  
  8. public static void main(String args[])
  9. {
  10. Scanner scan = new Scanner(System.in);
  11.  
  12. Point [] obj = new Point[NUM];
  13.  
  14. double [] dis = new double[NUM];
  15.  
  16.  
  17.  
  18. for (int i = 0 ; i < NUM ; i++)
  19. {
  20.  
  21. System.out.println("Please input No." + (i+1) + "point of its x and y value:");
  22.  
  23. int a = Integer.parseInt(scan.next());
  24.  
  25. int b = Integer.parseInt(scan.next());
  26.  
  27.  
  28. obj[i] = new Point(a,b);
  29. }
  30.  
  31.  
  32.  
  33. for (int i = 0 ; i < NUM ; i++)
  34. {
  35. System.out.println("No." + (i+1) + "'s distance with(0,0):" + obj[i].distance());
  36. }
  37.  
  38. dis[0] = obj[0].distance(obj[1]);
  39.  
  40. dis[1] = obj[1].distance(obj[2]);
  41.  
  42. dis[2] = obj[2].distance(obj[0]);
  43.  
  44. Arrays.sort(dis);
  45.  
  46. //if(
  47.  
  48.  
  49.  
  50. }
  51.  
  52.  
  53.  
  54.  
  55.  
  56. public class Point
  57. {
  58. private int x;
  59.  
  60. private int y;
  61.  
  62.  
  63. Point()
  64. {
  65.  
  66. }
  67.  
  68. Point(int x1,int y1)
  69. {
  70. x = x1;
  71. y = y1;
  72. }
  73.  
  74. public double distance()
  75. {
  76. return Math.sqrt(Math.pow(x,2) + Math.pow(y,2));
  77. }
  78.  
  79. public double distance(Point obj)
  80. {
  81. return Math.sqrt( Math.pow(this.x - obj.x,2) + Math.pow(this.y - obj.y,2) );
  82. }
  83.  
  84.  
  85.  
  86. public void setLocation(int a,int b,int c)
  87. {
  88. x = a;
  89. y = b;
  90. z = c;
  91. }
  92.  
  93.  
  94. public void setRadius(int r)
  95. {
  96. radius = r;
  97. }
  98.  
  99. public double surfaceArea()
  100. {
  101. return (4 * Math.PI * Math.pow(radius,2));
  102.  
  103. }
  104.  
  105. public double volume()
  106. {
  107. return (4 / 3 * Math.PI * Math.pow(radius,3));
  108. }
  109.  
  110. public void showCenter()
  111. {
  112. System.out.println("x=" + x + " y=" + y + " z=" + z);
  113. }
  114.  
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement