安卓实验电信二班310002831李硕.docx
- 文档编号:6568337
- 上传时间:2023-01-08
- 格式:DOCX
- 页数:12
- 大小:40.49KB
安卓实验电信二班310002831李硕.docx
《安卓实验电信二班310002831李硕.docx》由会员分享,可在线阅读,更多相关《安卓实验电信二班310002831李硕.docx(12页珍藏版)》请在冰豆网上搜索。
安卓实验电信二班310002831李硕
安卓实验-电信二班-310002831李硕
广东工业大学
广东工业大学实验报告
信息工程学院电子信息工程专业2班成绩评定_______
学号3110002831姓名:
李硕教师签名_______
预习情况
操作情况
考勤情况
数据处理情况
实验一
1、使用package语句和import语句
按照前面介绍的使用Eclipse输入、编译、调试程序的步骤,输入下面程序,然后编译、调试程序。
SquareEquation.java
packagetom.jiafei;
publicclassSquareEquation
{
doublea,b,c;
doubleroot1,root2;
booleanboo;
publicSquareEquation(doublea,doubleb,doublec)
{
this.a=a;
this.b=b;
this.c=c;
if(a!
=0)
{
boo=true;
}
else
{
boo=false;
}
}
publicvoidgetRoots()
{
if(boo)
{
System.out.println("是一元2次方程");
doubledisk=b*b-4*a*c;
if(disk>=0)
{
root1=(-b+Math.sqrt(disk))/(2*a);
root2=(-b-Math.sqrt(disk))/(2*a);
System.out.printf("方程的根:
%f,%f\n",root1,root2);
}
else
{
System.out.printf("方程没有实根\n");
}
}
else
{
System.out.println("不是一元2次方程");
}
}
publicvoidsetCoefficient(doublea,doubleb,doublec)
{
this.a=a;
this.b=b;
this.c=c;
if(a!
=0)
{
boo=true;
}
else
{
boo=false;
}
}
}
SunRise.java
//倒包即可
importtom.jiafei.*;
classSunRise
{
publicstaticvoidmain(Stringargs[])
{
SquareEquationequation=newSquareEquation(4,5,1);
equation.getRoots();
equation.setCoefficient(-3,4,5);
equation.getRoots();
}
}
2、继承
按照前面介绍的使用Eclipse输入、编译、调试程序的步骤,输入下面程序并完成未实现的代码,然后编译、调试程序。
packagecom.Example;
publicclassPeople
{
protecteddoubleweight,height;
publicvoidspeakHello()
{
System.out.println("yayawawa");
}
publicvoidaverageHeight()
{
height=173;
System.out.println("averageheight:
"+height);
}
publicvoidaverageWeight()
{
weight=70;
System.out.println("averageweight:
"+weight);
}
}
classChinaPeopleextendsPeople
{
//直接继承输出函数即可
publicvoidspeakHello()
{
System.out.println("你好,吃了吗");
}
//直接调用输出函数
publicvoidaverageHeight()
{
//只需改变数据值即可
height=168.78;
//单位是汉字,需要注意添加格式
System.out.println("中国人的平均身高:
"+height+"厘米");
}
publicvoidaverageWeight()
{
weight=65;
//直接继承输出函数,需要注意单位的添加方式
System.out.println("中国人的平均体重:
"+weight+"公斤");
}
publicvoidchinaGongfu()
{
//直接继承输出函数
System.out.println("坐如钟,站如松,睡如弓");
}
}
classAmericanPeopleextendsPeople
{
publicvoidspeakHello()
{
//直接继承输出函数
System.out.println("Howdoyoudo");
}
publicvoidaverageHeight()
{
height=178.78;
//直接继承输出函数
System.out.println("美国人的平均身高:
"+height+"厘米");
}
publicvoidaverageWeight()
{
//直接继承输出函数,并注意单位的添加
weight=75;
System.out.println("美国人的平均体重:
"+weight+"公斤");
}
publicvoidamericanBoxing()
{
//直接继承输出函数
System.out.println("直拳、钩拳");
}
}
classBeijingPeopleextendsChinaPeople
{
publicvoidspeakHello()
{
//直接继承输出函数
System.out.println("您好");
}
publicvoidaverageHeight()
{
//直接继承输出函数,并注意单位的添加
height=170.78;
System.out.println("北京人的平均身高:
"+height+"厘米");
}
publicvoidaverageWeight()
{
//直接继承输出函数,并注意单位的添加
weight=78;
System.out.println("北京人的平均体重:
"+weight+"公斤");
}
publicvoidbeijingOpera()
{
//直接继承输出函数
System.out.println("唱腔,身段,把式,生旦净丑");
}
publicstaticclassExample
{
//这是本程序的主函数,程序直接来此运行,当需要计算的时候再调用上面的程序
publicstaticvoidmain(Stringargs[])
{
ChinaPeoplechinaPeople=newChinaPeople();
AmericanPeopleamericanPeople=newAmericanPeople();
BeijingPeoplebeijingPeople=newBeijingPeople();
chinaPeople.speakHello();
americanPeople.speakHello();
beijingPeople.speakHello();
chinaPeople.averageHeight();
americanPeople.averageHeight();
beijingPeople.averageHeight();
chinaPeople.averageWeight();
americanPeople.averageWeight();
beijingPeople.averageWeight();
chinaPeople.chinaGongfu();
americanPeople.americanBoxing();
beijingPeople.beijingOpera();
beijingPeople.chinaGongfu();
}
}
}
3、接口回调
按照前面介绍的使用Eclipse输入、编译、调试程序的步骤,输入下面程序并完成未实现的代码,然后编译、调试程序。
packagecom.lishuo;
interfaceComputerWeight
{
publicdoublecomputeWeight();
}
classTelevisionimplementsComputerWeight
{
//实现computeWeight()方法。
publicdoublecomputeWeight()
{
//调用return关键词
return1.0;
}
}
classComputerimplementsComputerWeight
{
//实现computeWeight()方法。
publicdoublecomputeWeight()
{
//调用return关键词
return2.0;
}
}
classWashMachineimplementsComputerWeight
{
//实现computeWeight()方法。
publicdoublecomputeWeight()
{
//调用return关键词
return3.0;
}
}
classCar
{ComputerWeight[]goods;
doubletotalWeights=0;
Car(ComputerWeight[]goods)
{
this.goods=goods;
}
publicdoublegetTotalWeights()
{
totalWeights=0;
//计算totalWeights
//调用for函数进行计算
for(ComputerWeightgood:
goods)
{
totalWeights+=puteWeight();
}
returntotalWeights;
}
}
//这是本程序的主类,程序直接来此运行,当需要计算的时候,根据主类里面的指示去上面的方法里面去计算即可
publicclassRoad
{
publicstaticvoidmain(Stringargs[])
{ComputerWeight[]goodsOne=newComputerWeight[50],
goodsTwo=newComputerWeight[22];
for(inti=0;i {if(i%3==0) goodsOne[i]=newTelevision(); elseif(i%3==1) goodsOne[i]=newComputer(); elseif(i%3==2) goodsOne[i]=newWashMachine(); } for(inti=0;i {if(i%3==0) goodsTwo[i]=newTelevision(); elseif(i%3==1) goodsTwo[i]=newComputer(); elseif(i%3==2) goodsTwo[i]=newWashMachine(); } Car大货车=newCar(goodsOne); //输出结果 System.out.println("大货车载货物重量: "+大货车.getTotalWeights()); Car小货车=newCar(goodsTwo); System.out.println("小货车载货物重量: "+小货车.getTotalWeights()); }
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 实验 电信 310002831 李硕
![提示](https://static.bdocx.com/images/bang_tan.gif)