接口与实现:实验1
来源:互联网 发布:淘宝店铺粉丝怎么刷 编辑:程序博客网 时间:2024/05/29 12:51
接口:
package mypackage;public interface computerAverage {public abstract double average(double x[]);}
接口实现:
package mypackage;public class Gymnastics implements computerAverage {@Overridepublic double average(double[] x) {// TODO 自动生成的方法存根double average=0;int k= x.length;for(int i=1; i<k; i++){double temp;if(x[i-1]>x[i]){temp=x[i-1];x[i-1]=x[i];x[i]=temp;}}k--;for(int i=1; i<k; i++){average+=x[i];}k--;if(k > 2)average/=k;else average=0;return average;}}
package mypackage;public class School implements computerAverage {@Overridepublic double average(double[] x) {// TODO 自动生成的方法存根double average=0;int k= x.length;for(int i=0; i<k; i++){average+=x[i];}if(k > 2)average/=k;else average=0;return average;}}
主类:
package Main;import mypackage.*;public class main_class {public static void main(String[] args) {// TODO 自动生成的方法存根double a[] ={ 9.89, 9.88, 9.99, 9.12, 9.69, 9.76, 8.97};double b[] ={ 89, 56, 78, 90, 100, 77, 56, 45, 36, 79, 98};computerAverage k=new School();System.out.println("学校平均分:"+k.average(a));k=new Gymnastics();System.out.println("选手平均分:"+k.average(b));}}
阅读全文
0 0
- 接口与实现:实验1
- 接口与实现:实验2
- java实验六 接口与实现
- 接口与实验:实验3
- 数据库接口实验--php实现--
- 微型计算机原理与接口技术实验1.3.1
- 《C语言接口与实现》实验——链表(List_T)
- 《C语言接口与实现》实验——原子(Atom)
- 《C语言接口与实现》实验——表(Table_T)
- 《C语言接口与实现》实验——集合(Set_T)
- 《C语言接口与实现》实验——动态数组(Array_T)
- 《C语言接口与实现》实验——位向量(Bit_T)
- 《C语言接口与实现》实验——格式化(Fmt_T)
- 《C语言接口与实现》实验——低级字符串(Str_T)
- 《C语言接口与实现》实验——任意精度算术(AP_T)
- 《C语言接口与实现》实验——扩展精度算术(XP_T)
- 《C语言接口与实现》实验——高级字符串(Text_T)
- 《C语言接口与实现》实验——表(WF)
- Qt-你可以使用加农炮了
- Joda
- 使用Spring MVC统一异常处理实战
- [Azure] 使用azure cli 2.0 利用Key Vault创建自签名证书导入nginx
- Neural Networks神经网络个人小结与MATLAB实现
- 接口与实现:实验1
- 11月23日云栖精选夜读:阿里AI Labs王刚解读9小时卖出百万台的“天猫精灵”
- mt2503 [NETWORK]如何改为默认GPRS ALWAYS ON
- oracle定时执行存储过程
- css中的各种元素居中
- Android Listview中Button按钮点击事件冲突解决办法
- android自定义view学习资料
- GC专家系列目录索引
- JavaScript基础(二)