COMP204-07B Assignment 2
Your task is to implement a simple interactive application
which fits a regression line to data-points that ones enters
by just clicking inside a window. The regression line must
be updated after every newly added point.
Due date: Friday, 3rd August
What to submit:
One java file containing all you code.
Document your code well.
Use the javadoc @author tag to give your name and ID!
Specification:
Your application should consist of one graphical pane,
where the user can add points by just clicking.
A fitting line is easily computed by the following regression equation:
y = a + b*x
where a and b are computed as follows for n points:
a = s1 / d
b = s2 / d
s1 = (Sum y_i)*(Sum x_i*x_i) - (Sum x_i)*(Sum x_i*y_i)
s2 = n*(Sum x_i*y_i) - (Sum x_i)*(Sum y_i)
d = n*(Sum x_i*x_i) - (Sum x_i)*(Sum x_i)
You need at least TWO points to be able to fit a regression line.
Therefore you should wait until you have two or more points before
computing and drawing the regression line.
Assessment will be based on the following criteria:
- Functionality
- Reasonable clarity and style of programming.
- Reasonable documentation;
Here are a few hints:
- You can directly draw on a JFrame
- Class Graphics (the argument of your frame's paint method) has methods to draw lines and circles, and also to clear rectangular areas, among other methods.
- You will need some list to keep track of all the points.
- Class MouseEvent (the argument of your MouseListener's mousePressed method) has getX() and getY() methods
- The best way to draw your regression line is to simply draw from x:0/y:f(x) to x:width/y:f(width), where width is the width of your frame (see method getWidth).
- Frames can be formatted by method setPreferredSize(Dimension d), lookup class Dimension
- Closing your application window should quit your application (look at code examples)