我正在嘗試輸出一個(gè)數(shù)學(xué)函數(shù),但我不知道如何調(diào)用我的類來繪制/計(jì)算該函數(shù)。在主課中,我嘗試了以下public class GraphingProgram {public static void main(String[] args) { Applet program = new Applet(); program.setSize(300, 400); program.setName("Graphing Program"); GraphApplet testFunction = new GraphApplet(); program.add(testFunction); program.setVisible(true); } 班級(jí)代碼public class GraphApplet extends Applet{ double f(double x) { return (Math.cos(x/5) + Math.sin(x/7) + 2) * getSize().height/ 4; } public void paint (Graphics g) { for(int x = 0; x< getSize().width; x++) g.drawLine(x, (int) f(x), x+1, (int) f(x+1)); } public String getAppletInfo() { return "Draw a function graph"; } }執(zhí)行程序時(shí),我們應(yīng)該期望看到類的函數(shù)圖。例如,我應(yīng)該能夠在給定的間隔上輸出圖形 f(x) = cos(x/5) + sin(x/7) + 2,如下所示!https://i.imgur.com/przHRk6.png
添加回答
舉報(bào)
0/150
提交
取消