java 第五周实验【报告1】
2012-09-27 19:23
429 查看
1.封装一类三角形对象Triangle,该类对象具有三条边的属性,具有初始化三角形的功能、修改边长的功能、判断三条边能否构成三角形的功能、求周长的功能、求面积的功能。
public class TestTriangle { private double a,b,c; TestTriangle(double a,double b,double c){ this.a = a; this.b = b; this.c = c; } TestTriangle(){ this.a = 6; this.b = 8; this.c = 10; } public void set_edge(double a,double b,double c){ this.a = a; this.b = b; this.c = c; } public double get_Area(double a,double b,double c){ return (this.a+this.b+this.c); } public double get_Perimer(double a,double b,double c){ double s; s=(this.a+this.b+this.c)/2; return(Math.sqrt(s*(s-this.a)*(s-this.b)*(s-this.c))); } public boolean is_Triangle(double a,double b,double c) { if(this.a+this.b>this.c&&this.a+this.c>this.b&&this.c+this.b>this.a) { System.out.println("是三角形"); return true; } else{ System.out.println("不是三角形"); return false; } } public static void main(String[] args) { TestTriangle t = new TestTriangle(); t.get_Area(3,4,5); t.is_Triangle(3,4,5); t.get_Perimer(3,4,5); double c,x; c=t.get_Area(3, 4, 5); x=t.get_Perimer(3,4,5); System.out.println("面积为 "+c+" 周长为 "+x); } }
相关文章推荐
- Java第五周实验报告3
- Java第五周实验报告2
- java 第五周实验【报告3】
- java 第五周实验【报告2】
- Java第五周实验报告4
- Java第五周实验报告任务一【封装一类三角形对象Triangle】
- Java第五周实验报告1
- 山东大学Java程序设计课程实验报告5设计和使用类
- 20155337 《Java程序设计》实验一(Java开发环境的熟悉)实验报告
- JAVA--第五周实验--任务4--将三角形对象Triangle、梯形对象Ladder、圆形对象Circle进行测试。
- JAVA第五周实验(一).封装一类三角形对象Triangle
- 第四周 实验一 Java开发环境的熟悉 报告
- 20145122《 Java网络编程》实验五实验报告
- 20145307第五次JAVA学习实验报告
- 20145205 《Java程序设计》实验报告五:Java网络编程及安全
- 第五周实验报告(三)三角形类
- 《第五周实验报告4-1》---设计一个学生类,包括学号(num)和成绩(score)
- java第四次实验报告
- 第五周实验报告(任务一)《默认参数的构造函数》
- 第五周实验报告(一)参数列表