I'm doing an exercise in which I have to plot a function. I have to make a graph and show the graph of f(x)=x^3. The user gets to pick the maximum value of x that is shown on the graph, and also the size of the frame. So, for example, if the user picks 300 for the size, and 2.5 for the maximum value of x the output is shown here:

where I need help is how to plot the actual function. How do I know figure out what x and y coordinates to use for the function?
here is my code, I've highlighted exactly where I need help:
import javax.swing.JFrame; import java.util.Scanner; public class PlotFunction { static Scanner input = new Scanner(System.in); public static void main(String[] args){ System.out.print("Enter size of frame: "); int size = Integer.parseInt(input.nextLine()); System.out.print("Enter maximum value for x: "); double value = input.nextDouble(); input.nextLine(); JFrame frame = new JFrame("Plot Function"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); PlotFunctionPanel panel = new PlotFunctionPanel(size, value); frame.getContentPane().add(panel); frame.pack(); frame.setVisible(true); } }
panel class
import javax.swing.JPanel; import java.awt.*; public class PlotFunctionPanel extends JPanel{ int size; static double maxValue; public PlotFunctionPanel(int s, double v){ size = s; maxValue = v; setPreferredSize(new Dimension(size, size)); } public void paintComponent(Graphics g){ g.drawLine(size/2, 0, size/2, size); g.drawLine(0, size/2, size, size/2); double[] tick = getTicks(); int x = size/10, y = size/2, vA = 8; g.setFont(new Font("Sansserif", Font.PLAIN, size/30)); for(int i = 0; i < 9; i++){ g.drawLine(x, y+5, x, y-5); if(i != 4 && vA != 4){ if(i > 4) g.drawString(tick[i]+"", x-size/40, y+size/21); else g.drawString(tick[i]+"", x-size/30, y+size/21); if(vA > 4) g.drawString(tick[vA]+"", y-size/13, x+size/60); else g.drawString(tick[vA]+"", y-size/12, x+size/60); } g.drawLine(y+5, x, y-5, x); x+=size/10; vA--; } g.setColor(Color.RED); //This is where I need help, I'm almost completely lost. The function has to be plotted in red } //finds the values of the ticks on the axis e.g. -2.0, -1.5, -1.0, -0.5, 0.0, etc private static double[] getTicks(){ double increment = maxValue / 5, currentTick = -1*(maxValue); double[] tick = new double[9]; for(int i = 0; i < 9; i++){ currentTick+=increment; tick[i] = Math.round(currentTick*100.0)/100.0; } return tick; } }
thanks in advance