第四章例题4_3和4_4
来源:互联网 发布:制造业数据采集公司 编辑:程序博客网 时间:2024/06/06 09:12
class Lader
{
double above,bottom,height;
Lader(){}
Lader(double a,double b,double h){
above=a;
bottom=b;
height=h;
}
public void setAbove(double a){
above=a;
}
public void setBottom(double b){
bottom=b;
}
public void setHeight(double h){
height=h;
}
double computeArea(){
return(above+bottom)*height/2.0;
}
}
public class Example4_1{
public static void main(String args[]){
double area1=0,area2=0;
Lader laderOne,laderTwo;
laderOne=new Lader();
laderTwo=new Lader(10,88,20);
laderOne.setAbove(16);
laderOne.setBottom(26);
laderOne.setHeight(100);
laderTwo.setAbove(300);
laderTwo.setBottom(500);
area1=laderOne.computeArea();
area2=laderTwo.computeArea();
System.out.println("laderOne的above,bottom,height:"+
laderOne.above+","+laderOne.bottom+","+laderOne.height);
System.out.println("laderOne的面积:"+area1);
System.out.println("laderTwo的above,bottom,height:"+laderTwo.above+
","+laderTwo.bottom+","+laderTwo.height);
System.out.println("laderTwo的面积:"+area2);
}
}
结果:
---------- 运行 ----------
laderOne的above,bottom,height:16.0,26.0,100.0
laderOne的面积:2100.0
laderTwo的above,bottom,height:300.0,500.0,20.0
laderTwo的面积:8000.0
输出完成 (耗时 0 秒) - 正常终止
例4_4:
class Lader
{
double above,height;
static double bottom;
public void setAbove(double a){
above=a;
}
public void setBottom(double b){
bottom=b;
}
double getAbove(){
return above;
}
double getBottom(){
return bottom;
}
}
class Example4_4{
public static void main(String args[]){
Lader.bottom=60;
Lader laderOne,laderTwo;
System.out.println("现在所有Lader对象的bottom都是"+Lader.bottom);
laderOne=new Lader();
laderTwo=new Lader();
System.out.println("laderOne的bottom:"+laderOne.getBottom());
System.out.println("laderOne的bottom:"+laderOne.getBottom());
laderOne.setAbove(11);
laderTwo.setAbove(22);
laderTwo.setBottom(100);
System.out.println("现在所有的Lader对象的bottom都是:"+Lader.bottom);
System.out.println("laderOne的above:"+laderOne.getAbove());
System.out.println("laderTwo的above:"+laderTwo.getAbove());
}
}
结果:
---------- 运行 ----------
现在所有Lader对象的bottom都是60.0
laderOne的bottom:60.0
laderOne的bottom:60.0
现在所有的Lader对象的bottom都是:100.0
laderOne的above:11.0
laderTwo的above:22.0
输出完成 (耗时 0 秒) - 正常终止
- 第四章例题4_3和4_4
- Java第四章例题4_1和4_2
- 4_4
- 第四章 函数和递归例题
- 刷紫书第四章例题(例题4-4,4-5,4-6)
- 刷紫书第四章例题(例题4-1,4-2,4-3)
- 4_3
- 第四章例题练习
- 第四章例题
- 成员变量隐藏和方法重写5_3 5_4 5_5
- 4_4正整数类
- 《算法竞赛入门经典》第四章例题4-1 组合数
- 传热学第四版例题4-4数值算法计算器
- JavaScript权威指南_15_第4章_表达式和运算符_4.1-原始表达式
- JavaScript权威指南_19_第4章_表达式和运算符_4.5-调用表达式
- JavaScript权威指南_22_第4章_表达式和运算符_4.8-算术表达式
- JavaScript权威指南_23_第4章_表达式和运算符_4.9-关系表达式
- JavaScript权威指南_24_第4章_表达式和运算符_4.10-逻辑表达式
- Ant 指令说明
- mysql配置文件my.cnf详解[部分]
- C#中的关键字
- ANDROID GETTING STARTED WITH JB
- unbutu linux下安装VMware tools
- 第四章例题4_3和4_4
- POJ-3517-And Then There Was One
- Ant build.xml解析
- 11.2.0.3.1补丁升级学习
- 获取Android源码的简明步骤
- jQuery总结第二天
- Spring的分布式事务,使用或不用XA - 7
- 游戏手柄编程DEMO 基于 VB.NET+API 暂无力反馈
- tomcat虚拟路径的几种配置方法