point是java的简单介绍

博主:adminadmin 2022-12-09 20:27:09 124

今天给各位分享point是java的知识,其中也会对进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

java中声明Point类表示一个点的x轴和y轴坐标,声明若干get()和set()方法获得?

用JAVA声明类和接口,声明像素类Pixel继承Point类,因为像素是一个带颜色的坐标点。

具体代码:

public class Point implements Cloneable

{

private int x;

private int y;

// 不带参数的构造方法

public Point()

{

this(0, 0);

}

// 带参数的构造方法

public Point(int x, int y)

{

this.x = x;

this.y = y;

}

// 拷贝方法

@Override

protected Object clone() throws CloneNotSupportedException

{

return super.clone();

}

//set 和 get 方法

public int getX()

{

return x;

}

public void setX(int x)

{

this.x = x;

}

public int getY()

{

return y;

}

public void setY(int y)

{

this.y = y;

}

//move()方法

public void move(int x,int y)

{

this.x = this.x + x;

this.y = this.y + y;

}

}

Java定义一个Point(点)类

public class Point

{

public static void main(String[] args)

{

Point p1=new Point();

Point p2=new Point(1,2);

p1.show();

p1.move(3,4);

p1.show();

p2.show();

p2.move(5,6);

p2.show();

}

Point()

{

this(0,0);

}

Point(float x,float y)

{

this.x=x;

this.y=y;

}

void move(float x,float y)

{

this.x=x;

this.y=y;

}

void show()

{

System.out.printf("(%f,%f)",x,y);

System.out.println();

}

private float x,y;

}

定义一个Java类Point,用来描述平面直角坐标系中点的坐标。

需要两个类,一个Point,一个Test.这两个类,是调用和被调用的关系,Point被Test调用.

关系说好了,就是类具体实现的问题.

Point.java

这个类近似于常说的工具类或者辅助类.这里面既然对坐标操作就应该定义全局的x,y变量.其他的就是

方法.

public void setXY(double x,double y){

this.x = x;

this.y = y;

}

set方法就是类似于这样,把传过来的值赋给定义的全局.而get方法里面很显然就是return.

而测试类就是调用Point的过程.

class Point{

double x,y;

Point(){

System.out.println("enter a x value");

x = Console.readDouble();

System.out.println("enter a y value");

y = Console.readDouble();

}

Point(double a,double b){

x = a;

y = b;

}

}

class PointTest{

public static void main(String [] args){

Point p = new Point();

System.out.println("here is the point :");

System.out.println(p.x +" " + p.y);

}

}

Point p = new Point();

java问题 定义一个Point点类

public class Point {

    private int x;

    private int y;

    public Point(int x, int y) {

        this.x = x;

        this.y = y;

    }

    public int getX() {

        return x;

    }

    public void setX(int x) {

        this.x = x;

    }

    public int getY() {

        return y;

    }

    public void setY(int y) {

        this.y = y;

    }

    

    public double distance(Point p1,Point p2){

        return Math.sqrt((p2.getX()-p2.getX())*(p2.getX()-p2.getX())+(p2.getY()-p1.getY())*(p2.getY()-p1.getY()));

    }

    

    public static void main(String args[]){

        Point p1 = new Point(14,17);

        Point p2 = new Point(23,90);

        double s = p1.distance(p1,p2);

        System.out.println("2点之间的距离为:"+s);

    }

}

java 编程创建一个Point类

public class Test102 {

public static void main(String[] args) {

Point point = new Point();

point.printPoint();

point.moveTo(1, 3);

System.out.println("--移动后--");

point.printPoint();

}

}

class Point {

private float x;

private float y;

public Point() {

this.x = 0;

this.y = 0;

}

/**

* 移动到点(dest1,dest2)

* @param dest1

* @param dest2

*/

public void moveTo(float dest1, float dest2) {

this.x = dest1;

this.y = dest2;

}

public void printPoint() {

System.out.print("当前点坐标:" + "(" + x + "," + y + ")\n");

}

}

用JAVA定义一个描述点的point类.它有两个成员变量:横坐标x,纵坐标y

实现思路就是有一个类Point,之后这个类有两个私有成员变量,之后可以通过set和get方法进行赋值和数值读取:

public

class

Point

{

private

String

x;

private

String

y;

/**

*

默认构造函数

*/

public

Point(){

}

/**

*有x和y的构造方法。

*/

public

Point(String

x,String

y){

this.x=x;

this.y=y;

}

public

String

getX()

{

return

x;

}

public

void

setX(String

x)

{

this.x

=

x;

}

public

String

getY()

{

return

y;

}

public

void

setY(String

y)

{

this.y

=

y;

}

}

point是java的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、point是java的信息别忘了在本站进行查找喔。

The End

发布于:2022-12-09,除非注明,否则均为首码项目网原创文章,转载请注明出处。