收藏 分享(赏)

数据处理情况实验报告.docx

上传人:HR专家 文档编号:6123231 上传时间:2019-03-28 格式:DOCX 页数:17 大小:64.36KB
下载 相关 举报
数据处理情况实验报告.docx_第1页
第1页 / 共17页
数据处理情况实验报告.docx_第2页
第2页 / 共17页
数据处理情况实验报告.docx_第3页
第3页 / 共17页
数据处理情况实验报告.docx_第4页
第4页 / 共17页
数据处理情况实验报告.docx_第5页
第5页 / 共17页
点击查看更多>>
资源描述

1、广东工业大学广东工业大学实验报告信息工程 学院 电子信息工程 专业 2 班 成绩评定_学号 3110002831 姓名:李硕 教师签名_预习情况 操作情况 考勤情况 数据处理情况实验 一 1、使用 package 语句和 import 语句按照前面介绍的使用 Eclipse 输入、编译、调试程序的步骤,输入下面程序,然后编译、调试程序。SquareEquation.javapackage tom.jiafei;public class SquareEquation double a,b,c;double root1,root2;boolean boo;public SquareEquation

2、(double a,double b,double c) this.a=a;this.b=b;this.c=c;if(a!=0) boo=true; else boo=false;public void getRoots() if(boo) System.out.println(“是一元 2 次方程“);double disk=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,%fn“,root1,root2); else

3、System.out.printf(“方程没有实根 n“);elseSystem.out.println(“不是一元 2 次方程“); public void setCoefficient(double a,double b,double c)this.a=a;this.b=b;this.c=c;if(a!=0)boo=true; else boo=false;SunRise.java/倒包即可import tom.jiafei.*;class SunRise public static void main(String args ) SquareEquation equation=new S

4、quareEquation(4,5,1);equation.getRoots();equation.setCoefficient(-3,4,5);equation.getRoots();2、继承按照前面介绍的使用 Eclipse 输入、编译、调试程序的步骤,输入下面程序并完成未实现的代码,然后编译、调试程序。package com.Example;public class People protected double weight,height;public void speakHello()System.out.println(“yayawawa“); public void averag

5、eHeight() height=173;System.out.println(“average height:“+height);public void averageWeight()weight=70;System.out.println(“average weight:“+weight);class ChinaPeople extends People/直接继承输出函数即可public void speakHello()System.out.println(“你好,吃了吗“);/直接调用输出函数public void averageHeight()/只需改变数据值即可height=168

6、.78;/单位是汉字,需要注意添加格式 System.out.println(“中国人的平均身高 :“+height+“厘米“);public void averageWeight()weight=65;/直接继承输出函数,需要注意单位的添加方式System.out.println(“中国人的平均体重 :“+weight+“公斤“);public void chinaGongfu()/直接继承输出函数System.out.println(“坐如钟, 站如松,睡如弓“);class AmericanPeople extends Peoplepublic void speakHello()/直接继

7、承输出函数System.out.println(“How do you do“); public void averageHeight()height=178.78;/直接继承输出函数System.out.println(“美国人的平均身高 :“+height+“厘米“); public void averageWeight()/直接继承输出函数,并注意单位的添加weight=75;System.out.println(“美国人的平均体重:“+ weight+“公斤“ ); public void americanBoxing()/直接继承输出函数System.out.println(“直拳、

8、钩拳“ );class BeijingPeople extends ChinaPeople public void speakHello()/直接继承输出函数System.out.println(“您好“ );public void averageHeight()/直接继承输出函数,并注意单位的添加height=170.78;System.out.println(“北京人的平均身高 :“+height+“厘米“); public void averageWeight()/直接继承输出函数,并注意单位的添加weight=78;System.out.println(“北京人的平均体重:“+weig

9、ht+“公斤“ ); public void beijingOpera() /直接继承输出函数System.out.println(“唱腔,身段,把式,生旦净丑 “);public static class Example/这是本程序的主函数,程序直接来此运行,当需要计算的时候再调用上面的程序public static void main(String args)ChinaPeople chinaPeople=new ChinaPeople();AmericanPeople americanPeople=new AmericanPeople();BeijingPeople beijingPeo

10、ple=new BeijingPeople();chinaPeople.speakHello();americanPeople.speakHello();beijingPeople.speakHello();chinaPeople.averageHeight();americanPeople.averageHeight();beijingPeople.averageHeight();chinaPeople.averageWeight();americanPeople.averageWeight();beijingPeople.averageWeight();chinaPeople.chinaG

11、ongfu();americanPeople.americanBoxing();beijingPeople.beijingOpera() ;beijingPeople.chinaGongfu(); 3、接口回调按照前面介绍的使用 Eclipse 输入、编译、调试程序的步骤,输入下面程序并完成未实现的代码,然后编译、调试程序。package com.lishuo;interface ComputerWeightpublic double computeWeight();class Television implements ComputerWeight /实现 computeWeight()方法

12、。public double computeWeight() /调用 return 关键词return 1.0;class Computer implements ComputerWeight /实现 computeWeight()方法。public double computeWeight() /调用 return 关键词return 2.0; class WashMachine implements ComputerWeight /实现 computeWeight()方法。public double computeWeight() /调用 return 关键词return 3.0;clas

13、s Car ComputerWeight goods;double totalWeights=0;Car(ComputerWeight goods)this.goods=goods;public double getTotalWeights()totalWeights=0;/计算 totalWeights/调用 for 函数进行计算for(ComputerWeight good : goods) totalWeights += puteWeight();return totalWeights; /这是本程序的主类,程序直接来此运行,当需要计算的时候,根据主类里面的指示去上面的方法里面去计算即可

14、public class Roadpublic static void main(String args) ComputerWeight goodsOne=new ComputerWeight50,goodsTwo=new ComputerWeight22 ; for(int i=0;igoodsOne.length;i+) if(i%3=0)goodsOnei=new Television();else if(i%3=1)goodsOnei=new Computer();else if(i%3=2)goodsOnei=new WashMachine(); for(int i=0;igoodsTwo.length;i+) if(i%3=0)goodsTwoi=new Television();else if(i%3=1)goodsTwoi=new Computer();else if(i%3=2)goodsTwoi=new WashMachine(); Car 大货车=new Car(goodsOne);/输出结果 System.out.println(“大货车载货物重量 :“+大货车.getTotalWeights();Car 小货车=new Car(goodsTwo);System.out.println(“小货车载货物重量:“+ 小货车.getTotalWeights();

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 研究报告 > 农林牧渔

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报