java类的继承实验报告_Java实验报告(四)继承和多态

*

* @author Administrator

*/

import java.text.*;

public class Main {

public static void main(String[] args){

/*Shape[] shape1={new Circle(2.0),new Circle(3.0),new Circle(4.0),

new Circle(5.0),new Circle(6.0)};

Shape[] shape2={new Rectangle(1.0,2.0),new Rectangle(2.0,3.0),new Rectangle(3.0,4.0),

new Rectangle(4.0,5.0),new Rectangle(5.0,6.0)};

Shape shape3=new Circle(6.0);

Shape shape4=new Rectangle(10.0,10.0);*/

Shape[] shape1={new Circle(1.1),new Circle(1.2),new Circle(1.3),

new Circle(1.4),new Circle(1.5)};

Shape[] shape2={new Rectangle(1.0,4.0),new Rectangle(7.0,3.0),new Rectangle(3.0,5.0),

new Rectangle(9.0,5.0),new Rectangle(5.0,4.0)};

Shape shape3=new Circle(2.0);

Shape shape4=new Rectangle(9.5,5.0);

System.out.print("【排序面积从小到大】:\n");

sort(shape1);

sort(shape2);

System.out.print("【圆形数组】【长度】"+shape1.length);

for(int i=0;iSystem.out.println("【位置】"+i+shape1[i].toString());

}

System.out.println("【矩形数组】【长度】"+shape2.length);

for(int i=0;iSystem.out.println("【位置】"+i+shape2[i].toString());

}

int index=BinarySearch(shape1,shape3);

System.out.println("\n【二分法查找】:");

if(index==0){

System.out.println("【对象】"+shape3.toString()+"不存在【圆形】数组中。");

}

else{

System.out.println("【对象】"+shape3.toString()+

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值