Introduction to Java Programming编程题11.1<The triangle class>
来源:互联网 发布:道萨迪亚斯矩阵 编辑:程序博客网 时间:2024/06/14 11:02
运行结果:
Triangle: side1 = 1.0 side2 = 1.0 side3 = 1.0color: greenfilled: falseTriangle: side1 = 1.0 side2 = 1.5 side3 = 1.0color: yellowfilled: true
GeometricObject.java
package Uber;public class GeometricObject { private String color = "green"; private boolean filled = false; public GeometricObject() {} public GeometricObject(String color, boolean filled) { this.color = color; this.filled = true; } public String getColor() {return color;} public boolean getFilled() {return filled;} public void setColor(String color) {this.color = color;} public void setFilled(boolean filled) {this.filled = filled;}}
Triangle.java
package Uber;public class Triangle extends GeometricObject { private double side1; private double side2; private double side3; public Triangle() {side1 = side2 = side3 = 1;} public Triangle(double side1, double side2, double side3) { this.side1 = side1; this.side2 = side2; this.side3 = side3; } public void setSide(double side1, double side2, double side3) { this.side1 = side1; this.side2 = side2; this.side3 = side3; } public double getArea() { double p = (side1 + side2 + side3) / 2; return Math.sqrt(p * (p - side1) * (p - side2) * (p - side3)); } public double getPerimeter() {return side1 + side2 + side3;} public String toStr() { return "Triangle: side1 = " + side1 + " side2 = " + side2 + " side3 = " + side3; }}
TestTraingle.java
package Uber;public class TestTraingle { public static void main(String[] args) { Triangle one = new Triangle(); System.out.println(one.toStr() + "\ncolor: " + one.getColor() + "\nfilled: " + one.getFilled()); one.setColor("yellow"); one.setFilled(true); one.setSide(1, 1.5, 1); System.out.println(one.toStr() + "\ncolor: " + one.getColor() + "\nfilled: " + one.getFilled()); }}
0 0
- Introduction to Java Programming编程题11.1<The triangle class>
- Introduction to Java Programming编程题8.37<Guess the capitals>
- introduction to Java Programming 编程题5.3<回文整数>
- Introduction to Java Programming编程题5.6<打印数字三角形>
- Introduction to Java Programming编程题5.13<数列求和>
- Introduction to Java Programming编程题5.14<计算数列>
- Introduction to Java Programming编程题5.17<01矩阵>
- Introduction to Java Programming编程题5.26<回文素数>
- Introduction to Java Programming编程题5.27<反素数>
- Introduction to Java Programming编程题5.29<掷骰子游戏>
- Introduction to Java Programming编程题5.28<梅森素数>
- Introduction to Java Programming编程题5.30<双素数>
- Introduction to Java Programming编程题9.1<检查SSN>
- Introduction to Java Programming编程题9.2<检查子串>
- Introduction to Java Programming编程题7.6<两个矩阵相乘>
- Introduction to Java Programming编程题9.3<检验密码>
- Introduction to Java Programming编程题9.8<二进制转十进制>
- Introduction to Java Programming编程题9.9<二进制转十六进制>
- 找出List集合中不同的元素的方法
- JavaScript高级程序设计之基本概念之操作符之布尔操作符第3.5.3讲笔记
- JS-SDK设置安全域名
- 编程练习(2)
- angularjs结合bootstrap--进度条progressBar
- Introduction to Java Programming编程题11.1<The triangle class>
- SpriteBuilder切换解决方案以及CCB的修改与保存
- 低压mos大全
- 我的Unity项目遇到的坑
- 小马激活工具劫持火狐浏览器主页。
- 如何编写可读性好的代码
- IP地址
- Cortex-M3滴答定时器优先级设置
- 《深入理解Linux网络技术内幕》阅读笔记(五)