サイモン・キム:
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 {