简单的写一下,为了简单坐标都使用了int类型。
public class Point {
public int x;
public int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public static void show(Point p){
System.out.println("x: " + p.x + " y: " + p.y);
}
public static Point getMiddle(Point p1, Point p2){
int x = (p1.x + p2.x)/2;
int y = (p1.y + p2.y)/2;
Point p = new Point(x, y);
return p;
}
public static void main(String[] args) {
Point p1 = new Point(2, 4);
Point p2 = new Point(4, 4);
Point p = Point.getMiddle(p1, p2);
Point.show(p);
}
}
package com.test;
public class Point {
/*
* property dou ble x,y
*/
public double x;
public double y;
/*
* Point()
*/
public Point(double d, double y) {
this.x = d;
this.y = y;
}
/*
* type: static
* return: void
* arg: Point
*/
public static void show(Point p){
System.out.println("x: " + p.x + " y: " + p.y);
}
/*
*
* return: void
*
*/
public void show(){
System.out.println("x: " + this.x + " y: " + this.y);
}
/*
* type: static
* return: Point
* arg: Point,Point
*/
public static Point getMiddle(Point p1, Point p2){
double x = (p1.x + p2.x)/2;
double y = (p1.y + p2.y)/2;
Point p = new Point(x, y);
return p;
}
/*
* main()
*/
public static void main(String[] args) {
Point p1 = new Point(6.5, 2.9);
Point p2 = new Point(8.4, 6.4);
Point newp = Point.getMiddle(p1, p2);
newp.show();
}
}