Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.Math;
- public class Q5_4
- {
- private static final int NUM = 3;
- public static void main(String args[])
- {
- Scanner scan = new Scanner(System.in);
- Point [] obj = new Point[NUM];
- double [] dis = new double[NUM];
- for (int i = 0 ; i < NUM ; i++)
- {
- System.out.println("Please input No." + (i+1) + "point of its x and y value:");
- int a = Integer.parseInt(scan.next());
- int b = Integer.parseInt(scan.next());
- obj[i] = new Point(a,b);
- }
- for (int i = 0 ; i < NUM ; i++)
- {
- System.out.println("No." + (i+1) + "'s distance with(0,0):" + obj[i].distance());
- }
- dis[0] = obj[0].distance(obj[1]);
- dis[1] = obj[1].distance(obj[2]);
- dis[2] = obj[2].distance(obj[0]);
- Arrays.sort(dis);
- //if(
- }
- public class Point
- {
- private int x;
- private int y;
- Point()
- {
- }
- Point(int x1,int y1)
- {
- x = x1;
- y = y1;
- }
- public double distance()
- {
- return Math.sqrt(Math.pow(x,2) + Math.pow(y,2));
- }
- public double distance(Point obj)
- {
- return Math.sqrt( Math.pow(this.x - obj.x,2) + Math.pow(this.y - obj.y,2) );
- }
- public void setLocation(int a,int b,int c)
- {
- x = a;
- y = b;
- z = c;
- }
- public void setRadius(int r)
- {
- radius = r;
- }
- public double surfaceArea()
- {
- return (4 * Math.PI * Math.pow(radius,2));
- }
- public double volume()
- {
- return (4 / 3 * Math.PI * Math.pow(radius,3));
- }
- public void showCenter()
- {
- System.out.println("x=" + x + " y=" + y + " z=" + z);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement