以点类Point及平面图形类Plane为基础设计三角形类Triangle

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

怀孕能吃银耳吗以点类Point及平⾯图形类Plane为基础设计三⾓形类Triangle 学习内容:以点类 Point 及平⾯图形类 Plane 为基础设计三⾓形类 Triangle
代码⽰例:
import java.util.Scanner;对你的思念是一天又一天
class Point{
private double x;
private double y;
public Point(double x,double y) {
this.x=x;
this.y=y;
System.out.println("Point Constructor run");
}
public void tX(double x) {//设置x坐标
this.x=x;
}
public final double getX(){//返回x坐标
return x;
}
public void tY(double y) {//设置y坐标
this.y=y;
}
public final double getY(){//返回y坐标
return y;
}
public void show() {//显⽰点的坐标
苏联为什么解体System.out.print("Point(X="+x+",Y="+y+")");
}
public double dis(Point p)
{
double _x = Math.abs(this.x - p.x);
double _y = Math.abs(this.y - p.y);
return Math.sqrt(_x*_x+_y*_y);
}
}
abstract class Plane{//抽象类Plane
double length() {
return 0;
}
double area() {
return 0;
}
}
public class Triangle extends Plane {
private Point a;
private Point b;
private Point c;
public Triangle(final Point a, final Point b, final Point c) {
this.a=a;
this.b=b;
this.c=c;
System.out.println("Triangle Constructorrun");
}
public void tA(final Point a) {
this.a=a;
}
public Point getA() {
雨果圆明园
return a;
}
public void tB(final Point b) {
this.b=b;
}
public Point getB() {
硅胶内衣return b;
}
public void tC(final Point c) {
this.c=c;
}
public Point getC() {
return c;
}
public final void show() {
System.out.print("Triangle(A=");
a.show();
System.out.print(",B=");
b.show();
System.out.print(",C=");
c.show();
}
final double area() {
double l1, l2, l3,s;
l1 = a.dis(b);
l2 = a.dis(c);
l3 = b.dis(c);
s = (l1 + l2 + l3) / 2;
double area=Math.sqrt(s * (s - l1) * (s - l2) * (s - l3));
System.out.println("Area="+area);
return 0;
}
final double length() {
double l1=a.dis(b);
double l2=a.dis(c);
double l3=b.dis(c);
double length=l1+l2+l3;
System.out.println("length="+length);
return 0;
}
谅解协议书public static void main(String[] args) {
double x,y;
Point p1=new Point(0, 0);
Point p2=new Point(1, 1);
Point p3=new Point(2, 2);
Triangle t1=new Triangle(p1, p1, p1);
Triangle t2=t1;
t1.show();
System.out.println();//换⾏淮山排骨汤的做法
t1.area();
t1.length();
Scanner sc=new Scanner(System.in);
System.out.println("请输⼊x,y:");
Double();
Double();
最小的花
p1.tX(x);
p1.tY(y);
t2.tA(p1);
t2.tB(p2);
t2.tC(p3);
t2.show();
System.out.println();
t2.area();
t2.length();
}
}
运⾏截图:
遇到的问题:⾯积函数采⽤“return Math.sqrt(s * (s - l1) * (s - l2) * (s - l3));”的形式⽆法输出⾯积
解决⽅法:设置变量area,使area=Math.sqrt(s * (s - l1) * (s - l2) * (s - l3));输出area,返回值设为0明天任务:以圆类 Circle 及⽴体图形类 Solid 为基础设计球类 Sphere

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

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

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

标签:基础   设置   形类   坐标   设计   问题   输出   任务
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图