java课后习题point类

更新时间:2023-07-14 07:17:14 阅读: 评论:0

java课后习题point类
完成教材P116 三 编程题 3 (设计Point类…)
梨花几月份开花
题⽬描述:
Demo类⽤于测试,通过键盘输⼊两个点的坐标,求它们的距离
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
Point p1=new Point();
System.out.println("plea input the first point's (x,y):");
p1.Double());
p1.Double());
Point p2=new Point();
System.out.println("plea input the Second point's (x,y):");
p2.Double());
p2.Double());
忙的成语System.out.println("The distance is "+p1.getDistance(p2));
Point3D p3=new Point3D();
System.out.println("plea input the first point's (x,y,z):");
p3.Double());
p3.Double());
p3.Double());
Point3D p4=new Point3D();
System.out.println("plea input the Second point's (x,y,z):");
p4.Double());
p4.Double());
p4.Double());
System.out.println("The distance is "+p3.getDistance(p4));
资治通鉴白话文sc.clo();
}
}
眉毛简笔画
这是我们所需要的Point类
Point和Point3D类
public class Point {
double x;
double y;
幼儿教育知识
public void tX(double x){
this.x = x;
}
public void tY(double y){托班安全教育教案
this.y = y;
}
public double getX(){
return x;
}
顾亚龙public double getY(){
return y;
}
public double getDistance(Point p2){
return Math.sqrt((this.x-p2.x)*(this.x-p2.x)+(this.y-p2.y)*(this.y-p2.y));
}
}
class Point3D extends Point{
double z;
public void tZ(double z){
this.z = z;
}
public double getZ(){
return z;
}
//⽅法重写
public double getDistance(Point3D p3){
return Math.sqrt((this.x-p3.x)*(this.x-p3.x)+(this.y-p3.y)*(this.y-p3.y)+(this.z-p3.z)*(this.z-p3.z)); }
}
证婚人致辞

本文发布于:2023-07-14 07:17:14,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1080875.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:教育   教材   梨花   键盘   简笔画   证婚人
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图