Subato

FunGraph (freiwillige Zusatzaufgabe)

import java.util.function.Function;
public final class FunGraph {
  private FunGraph(){}
  
  static String mkStringGraph(Function<Double,Double> f,int xMin,int xMax,int yMin,int yMax){

    String result="";
    for (int y=yMax;y>= yMin;y--){
      for (int x= xMin;x <= xMax;x++){
      if ( f.apply((double)x).intValue()<=y && f.apply((double)x+1).intValue()>=y 
         ||  f.apply((double)x).intValue()<=y && f.apply((double)x-1).intValue()>=y){
          result+="*";
        }else if(x==0){
          result+="|";          
        }else if(y==0){
          result+="-";          
        }else{
          result+=" ";          
        }
      }
      result += "\n";
    }
    return result;
  }
}