public class FunctionManager { private int aLinear, bLinear, aSquare, bSquare, cSquare; private static final int X_START = -10; private static final int X_STOP = 10; private static final int X_STEP = 1; private static final int Y_START = -10; private static final int Y_STOP = 10; private static final int Y_STEP = 1; public FunctionManager(int aLinear, int bLinear, int aSquare, int bSquare, int cSquare) { this.aLinear = aLinear; this.bLinear = bLinear; this.aSquare = aSquare; this.bSquare = bSquare; this.cSquare = cSquare; printGraph(); } private void printGraph() { for (int y = Y_START;y<= Y_STOP;y+=Y_STEP) { // Blok pro průchod s konkrétní hodnotou y buildRow(y); System.out.println(); } printXAxis(); } private void printXAxis() { System.out.print(" "); for (int x=X_START; x<= X_STOP; x+= X_STEP){ System.out.print(String.format("%-5s",x)); } } private void buildRow(int y) { printYAxis(y); for(int x = X_START; x<= X_STOP;x+=X_STEP){ // Blok pro průchod s konkrétní hodnotou x a y buildPoint(x,y); } } private void buildPoint(int x, int y) { boolean isLinear = testIfLinearFunctionIsHit(x,y); boolean isSquare = testIfSquareFunctionIsHit(x,y); if(isLinear && isSquare) { System.out.print(" ~ "); } else if (isLinear && (!isSquare)) { System.out.print(" - "); } else if((!isLinear) && isSquare){ System.out.print(" * "); } else { System.out.print(" "); } } private boolean testIfSquareFunctionIsHit(int x, int y) { return g(x) == y; } private boolean testIfLinearFunctionIsHit(int x, int y) { return f(x) == y; } private int f(int x) { // return linear function return aLinear * x + bLinear; } private int g(int x){ return aSquare * x * x + bSquare * x + cSquare; } private void printYAxis(int y) { System.out.print(String.format("%-5s",y)); } }