java 程序 动物奥运会

2022-06-09 06:45:29   第一文档网     [ 字体: ] [ 阅读: ] [ 文档下载 ]
说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。下载word有问题请添加QQ:admin处理,感谢您的支持与谅解。点击这里给我发消息

#第一文档网# 导语】以下是®第一文档网的小编为您整理的《java 程序 动物奥运会》,欢迎阅读!
奥运会,动物,程序,java

package com.animalMatch; /**



* 动物奥运会

* @author liuwei

* @date 2010-04-29 */

public class Client {

public static void main(String[] args) {

Runway r = new Runway(100.00) ;//100米赛道

Animal a1 = new Flight("冥界亚龙",1.0);

Animal a2 = new Reptiles("影魔",0.6);

Animal a3 = new Swimming("鱼人守卫",0.9);

Animal a4 = new Reptiles("龙骑士",4.0);

Animal a5 = new Reptiles("炸弹人",0.1);

Committee o = new Committee(r);

o.put(a1);

o.put(a2);

o.put(a3);

o.put(a4);

o.put(a5);

o.game();


o.output();

} }

package com.animalMatch; /**



* 抽象动物类

* @author liuwei *

*/

public abstract class Animal {



private String name;//动物的名字



private double value;//动物的翅膀长度,四肢强壮度,尾巴长度

double speed;

public Animal(String name, double value) {

this.name = name;

this.value = value;

}

public String getName() {

return this.name;

}

public double getValue() {

return this.value; }

public abstract double getSpeed();

public abstract double time(Runway r); }

package com.animalMatch;




import java.util.*;

import java.text.DecimalFormat; public class Committee { private Runway r;

private Map tm1 = new HashMap<Animal,String>(); private TreeMap

tm2

=

new TreeMap(new

Comparator(){

public int compare(Animal o1, Animal o2) { if(o1.time(r) > o2.time(r)) return 1; else

return -1; } } );

public Committee(Runway r){ this.r = r ; }

public void put(Animal o1) {//报名

this.tm1.put(o1, o1.getName()); }

public void game(){//组织比赛

Set keySet = this.tm1.keySet(); for(Animal o:keySet)

this.tm2.put(o, o.getName()); }

public void output() {//输出

DecimalFormat df1=new DecimalFormat("0"); String as=df1.format(r.getLength()); System.out.println(as+"米赛跑成绩"); int i = 1;

Set keySet = this.tm2.keySet(); for(Animal o:keySet){

DecimalFormat df=new DecimalFormat("0.00"); as=df.format(o.time(r));

System.out.println(""+i+": "+o.getName()+ " "+as+""); i++; } } }

package com.animalMatch; /**


本文来源:http://www.dywdw.cn/fd714817866fb84ae45c8d00.html

相关推荐
推荐阅读