Knocks the error that the method does not exist

File one:

import edu.san.stats.AverageCalcAware; import edu.san.stats.MaxMinCalcAware; import edu.san.stats.MedianCalcAware; public class BigDecimalStats{ private int BigDecimal[]; public BigDecimalStats(int BigDecimal[] ) { this.BigDecimal = BigDecimal; } public class Average implements AverageCalcAware{ @Override public java.math.BigDecimal calcMedian() { return null; } } public class MaxMin implements MaxMinCalcAware{ @Override public java.math.BigDecimal calcMax() { int max = (int) Double.MIN_VALUE; for (int i = 0; i < BigDecimal.length; i++) { max = Math.max(max, BigDecimal[i]); } return calcMax(); } @Override public java.math.BigDecimal calcMin() { return null; } } public class Median implements MedianCalcAware{ @Override public java.math.BigDecimal calcAverage() { return null; } } 

File second (output):

 public class StatsCalc { public static void main(String[] args) { int [] big = {1,2,3,1,5,6}; BigDecimalStats stats = new BigDecimalStats(big); for (int i = 0; i < big.length; i++) { System.out.println(big[i] + " "); } System.out.println(String.format("Max: " + stats.calcMax())); } } 

An error occurs when calling stats.calcMax() :

Multiple markers at this line - MaxMin cannot be resolved or is not a field

  • 2
    What is actually wrong and what is the question? - Viktorov
  • It knocks out that the calcMax () method does not exist, in the second file - CHEATER
  • Multiple markers at this line - MaxMin cant be resolved or not - CHEATER
  • You can make the method static, but it will not work anyway, since it calls itself. - Roman C

1 answer 1

The calcMax() method is defined in the MaxMinCalcAware interface. This interface is implemented by the MaxMin class, but not the BigDecimalStats class. You need to access an object of type MaxMinCalcAware , or implement the interface in the BigDecimalStats class itself.

PS: I advise you not to call class variables like this: private int BigDecimal[]; - remove from the name BigDecimal

  • Need to create a new MaxMinCalcAware object first? - CHEATER
  • one
    you need to implement the specified interfaces inside your BigDecimalStats class and not create nested classes, but also read and read the literature again! - JVic