Why is my method undefined for this type?

Simon Kim :

I'm not sure why Eclipse is giving me this error, I cannot run the exchange method for any of my desired classes:

The method exchange(Currency, double) is undefined for the type Currency

Some of the code methods listed have not been fully implemented due to my issues compiling to begin with.

What simple mistake am I making?

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);
  }
}
Elliott Frisch :

Your abstract Currency class does not implement the Exchangeable interface. Change

public abstract class Currency {

to

public abstract class Currency implements Exchangeable {

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=11724&siteId=1