なぜ私の方法は、このタイプのために定義されていませんか?

サイモン・キム:

Eclipseは私にこのエラーを与えている理由は、私はわからないんだけど、私は私の希望クラスのいずれかのための交換方法を実行することはできません。

メソッドの交換は(通貨、ダブル)タイプの通貨のために定義されていません

コードの方法のいくつかは完全に私の問題は、そもそもコンパイルのために実装されていない記載されています。

私は何単純なミスを作っていますか?

public abstract class Currency {
  String currencyName;
  double totalFunds;

  //Exchange money between planets
  public abstract double toEarthDollars(double amount);

  public abstract double fromEarthDollars(double EarthDollars); 

  public static void main(String[] args) {
    //TEST INPUT CODE
    Currency mars = new Mars(100.00);
    Currency neptune = new Neptune(100.00);
    Currency saturn = new Saturn(100.00);

    System.out.println("----- Exchanges -----");

    mars.exchange(saturn,25.0);
    neptune.exchange(saturn, 10.0);
    saturn.exchange(mars, 122.0);
    saturn.exchange(mars, 121.0);
  }
} 


public interface Exchangeable {
  //rates should be encapsulated and accessed from here
  double EarthDollar = 1;
  double MarsMoney = 1.3;
  double SaturnSilver = 0.87;
  double NeptuneNuggets = 2;

  public void exchange(Exchangeable other, double amount);
}


public class Mars extends Currency implements Exchangeable {
  public Mars(double amount) {
    currencyName = "MarsMoney";
    totalFunds = amount;
  }

  public double toEarthDollars(double amount) {
    return amount * (Exchangeable.EarthDollar/Exchangeable.MarsMoney);
  }

  public double fromEarthDollars(double EarthDollars) {
    return EarthDollars * (Exchangeable.MarsMoney/Exchangeable.EarthDollar);
  }

  public void exchange(Exchangeable other, double amount) { 
    System.out.println("Hello");
    //double transfer = this.toEarthDollars(amount);
    //transfer = ((Mars) other).fromEarthDollars(transfer);
  }
}
エリオットの新鮮:

あなたの抽象Currencyクラスが実装されていないExchangeableインターフェイスを。変化する

public abstract class Currency {

public abstract class Currency implements Exchangeable {

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=13418&siteId=1