javapoint,javapoint类的声明

本文目录一览:

关于JAVA的point的题 急!!!!!

public class Point {�

private double x, y;�

public point(){}//当你在类中写出有参构造之后,系统不会再分配一个无参构造给该类。

public Point(double a, double b) {

setPoint(a, b);

}�

public void setPoint(double a, double b) {�

x=a;�

y=b;�

}�

public double getX() {return x;}

public double getY() {return y;}�

}�

public class Line extends Point {�

private double x, y, endX, endY;�

public Line(){}

public Line(double x1, double y1, double x2, double y2) {

super(x1,y1);//调用父类构造,若不写,子类调用的是父类的默认构造

public setLine(x1, y1, x2, y2);

}�

public void setLine(double x1, double y1, double x2, double y2) {�

x=x1;�

y=y1;�

endX=x2;�

endY=y2;�

}�

public double getX() {return x ;}�

public double getY() {return y ;}�

public double getEndX() {return endX;}�

public double getEndY() {return endY;}�

public double length() {�

return Math.sqrt((endX-x) * (endX-x) + (endY-y) * (endY-y));

}�

}

public class Circle extends Point {�

private double radius; // 子类受保护的成员变量,代表圆的半径�

public Circle(double radius){

} // 圆的构造方法�

public Circle(){

}

public void setRadius(double radius){

this.radius = radius;

} // 设定半径值的方法�

public double getRadius(){

return radius;

} // 返回半径值的方法�

public double area(){

return 3.14*radius*radius

} // 返回圆面积的方法�

}

改动有如下几点:int全部改为double

添加默认的构造,因为在子类中不写调用父类的构造,系统也会先去调用父类的默认构造。

为了良好的封装性,属性的修饰符都为private

若有问题,可以联系我。

定义一个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的test中加入修改坐标点point的方法up

怎么在java的test中加入修改坐标点point的方法up如下:

1、首先打开java软件的test考察板块。

2、然后点击自定义坐标设置,选择point坐标点逐个修改设置参数。

3、最后修改后的参数点击左下方确定即可。

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类

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”);

}

}

原创文章,作者:小蓝,如若转载,请注明出处:https://www.506064.com/n/150765.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
小蓝小蓝
上一篇 2024-11-09 02:14
下一篇 2024-11-09 02:14

相关推荐

发表回复

登录后才能评论