java编程。Point类有double型的x和y两个私有成员变量,有对它们进行读写的公有方法, 20
该类还有一个对x和y进行初始化的构造方法,还有一个公有的getDistanceFromOrigin()方法(求到左边原点的距离),在主类中创建一个点对象,输出其到原点的距...
该类还有一个对x和y进行初始化的构造方法,还有一个公有的getDistanceFromOrigin()方法(求到左边原点的距离),在主类中创建一个点对象,输出其到原点的距离
急急急急急 展开
急急急急急 展开
1个回答
展开全部
public class Point{
private double x;
private double y;
public Point(double x, double y){
this.x = x;
this.y = y;
}
public double getDistanceFromOrigin(){
return Math.sqrt((Math.pow(x, 2) + Math.pow(y, 2)));
}
public static void main(String[] args){
Point p = new Point(3, 4);
System.out.println(p.getDistanceFromOrigin());
}
public double getX()
{
return x;
}
public void setX(double x)
{
this.x = x;
}
public double getY()
{
return y;
}
public void setY(double y)
{
this.y = y;
}
}
private double x;
private double y;
public Point(double x, double y){
this.x = x;
this.y = y;
}
public double getDistanceFromOrigin(){
return Math.sqrt((Math.pow(x, 2) + Math.pow(y, 2)));
}
public static void main(String[] args){
Point p = new Point(3, 4);
System.out.println(p.getDistanceFromOrigin());
}
public double getX()
{
return x;
}
public void setX(double x)
{
this.x = x;
}
public double getY()
{
return y;
}
public void setY(double y)
{
this.y = y;
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询