好文档 - 专业文书写作范文服务资料分享网站

Java语言程序设计(基础篇)原书第十一版 梁勇 第11章 课后题答案

天下 分享 时间: 加入收藏 我要投稿 点赞

11.1Trianfle

public class GeometricObject { private String color=\ private boolean filled=false; public GeometricObject(){ }

public GeometricObject(String color,boolean filled){ this.color=color; this.filled=filled; }

public boolean isFilled(){

if (this.color != null) filled=true; return filled; }

public void setColor(String color) { this.color = color; }

public String toString() { isFilled();

return \颜色及是否填充{\ \ \ '}'; } }

public class Triangle extends GeometricObject { double side1; double side2; double side3; public Triangle(){ side1=1; side2=1; side3=1; }

public Triangle(double side1,double side2,double side3){ this.side1=side1; this.side2=side2; this.side3=side3; }

public double getSide1() { return side1; }

public double getSide2() { return side2; }

public double getSide3() { return side3; }

public double getPerimeter(){ return side1+side2+side3; }

public double getArea(){

double a=getPerimeter()/2;

double b=a*(a-side1)*(a-side2)*(a-side3); return Math.pow(b,0.5); }

public String toString() { return \三边为{\

\ \ \ \ } }

public class Test {

public static void main(String[] args) {

Triangle triangle=new Triangle(3,4,5); triangle.setColor(\

System.out.println(\面积为\

System.out.println(\周长为\ System.out.println(triangle.toString());

} }

Java语言程序设计(基础篇)原书第十一版 梁勇 第11章 课后题答案

11.1TrianflepublicclassGeometricObject{privateStringcolor=\privatebooleanfilled=false;publicGeometricObject(){}publicGeometricObject(Stringcolor,boole
推荐度:
点击下载文档文档为doc格式
6sqjy2tj7703gjy5zd2f62h6002tp400l6r
领取福利

微信扫码领取福利

微信扫码分享