您好我有一个java作业不太会做,能麻烦帮我解答一下么,时间比较急,下午两点前due

这是老师给的压缩包的原文件http://pan.baidu.com/s/1sjrxPiH这个是作业要求http://pan.baidu.com/s/1c0zVOBm如果大... 这是老师给的压缩包的原文件http://pan.baidu.com/s/1sjrxPiH
这个是作业要求http://pan.baidu.com/s/1c0zVOBm

如果大神可以帮忙,万分感谢
展开
 我来答
华兴兴华
2014-10-24 · TA获得超过189个赞
知道小有建树答主
回答量:297
采纳率:100%
帮助的人:223万
展开全部

你们老师让你完成他给的代码,做成这样~我试试

需要修改两个文件的代码:第一个:Cache.java


package cs1410;

public class Cache
{
  private String code;
  private String title;
  private String owner;
  private double difficulty;
  private double terrain;
  private String latitude;
  private String longitude;

  public Cache(String attributes)
  {
    String[] attrs = attributes.split("\t");
    if (attrs.length != 7)
    {
      throw new IllegalArgumentException();
    }

    this.code = attrs[0];
    this.title = attrs[1];
    this.owner = attrs[2];
    try
    {
      this.difficulty = Double.parseDouble(attrs[3]);
      this.terrain = Double.parseDouble(attrs[4]);
    }
    catch (NumberFormatException e)
    {
      throw new IllegalArgumentException();
    }
    this.latitude = attrs[5];
    this.longitude = attrs[6];
  }

  public String toString()
  {
    return getTitle() + " by " + getOwner();
  }

  public String getOwner()
  {
    return this.owner;
  }

  public String getTitle()
  {
    return this.title;
  }

  public double getDifficulty()
  {
    return this.difficulty;
  }

  public double getTerrain()
  {
    return this.terrain;
  }

  public String getGcCode()
  {
    return this.code;
  }

  public String getLatitude()
  {
    return this.latitude;
  }

  public String getLongitude()
  {
    return this.longitude;
  }
}


第二个CacheList.java:


package cs1410;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Scanner;

public class CacheList
{
  private ArrayList<Cache> allCaches;
  private double minTerr;
  private double maxTerr;
  private double minDiff;
  private double maxDiff;
  private String ownerConstraint;
  private String titleConstraint;

  public CacheList(Scanner caches)
    throws IOException
  {
    this.allCaches = new ArrayList();
    int line = 1;
    try
    {
      while (caches.hasNextLine())
      {
        this.allCaches.add(new Cache(caches.nextLine()));
        line++;
      }
    }
    catch (IllegalArgumentException e)
    {
      throw new IllegalArgumentException(e);
    }

    Collections.sort(this.allCaches, new CacheComparator());

    this.minTerr = 1.0D;
    this.maxTerr = 5.0D;
    this.minDiff = 1.0D;
    this.maxDiff = 5.0D;
    this.ownerConstraint = "";
    this.titleConstraint = "";
  }

  public void setTitleConstraint(String title)
  {
    this.titleConstraint = title;
  }

  public void setOwnerConstraint(String owner)
  {
    this.ownerConstraint = owner;
  }

  public void setDifficultyConstraints(double min, double max)
  {
    this.minDiff = min;
    this.maxDiff = max;
  }

  public void setTerrainConstraints(double min, double max)
  {
    this.minTerr = min;
    this.maxTerr = max;
  }

  public ArrayList<Cache> select()
  {
    ArrayList caches = new ArrayList();
    for (Cache c : this.allCaches)
    {
      if ((!c.getTitle().contains(this.titleConstraint)) ||
        ((!this.ownerConstraint.equals("")) &&
        (!c.getOwner().equals(
        this.ownerConstraint))) || (c.getDifficulty() < this.minDiff) ||
        (c.getDifficulty() > this.maxDiff) ||
        (c.getTerrain() < this.minTerr) || (c.getTerrain() > this.maxTerr))
        continue;
      caches.add(c);
    }

    return caches;
  }

  public ArrayList<String> getOwners()
  {
    HashSet ownerSet = new HashSet();
    for (Cache c : this.allCaches)
    {
      ownerSet.add(c.getOwner());
    }
    ArrayList owners = new ArrayList(ownerSet);
    Collections.sort(owners, new StringComparator());
    return owners;
  }

  private class CacheComparator
    implements Comparator<Cache>
  {
    public int compare(Cache c1, Cache c2)
    {
      return c1.getTitle().compareToIgnoreCase(c2.getTitle());
    }
  }

  private class StringComparator
    implements Comparator<String>
  {
    public int compare(String s1, String s2)
    {
      return s1.compareToIgnoreCase(s2);
    }
  }
}


把我给的两个文件代码替换后运行绝对和你老师的一样效果。

这是我本地运行结果:

本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
brother__qiang
2014-10-24 · TA获得超过597个赞
知道小有建树答主
回答量:1346
采纳率:66%
帮助的人:529万
展开全部

我的个妈,全英文

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式