Question: (ONLY USE MULTIDIMENSIONAL ARRAY TO STORE THE VALUE X,Y AS WELL AS DISPLAY THE SCATTERPLOT) Write a complete Java program that draws a scatterplot by
(ONLY USE MULTIDIMENSIONAL ARRAY TO STORE THE VALUE X,Y AS WELL AS DISPLAY THE SCATTERPLOT)
Write a complete Java program that draws a scatterplot by reading in points of data from a file and displaying them. The input data file consists of a pair of integers representing a point on each line of the file; the first integer is the x coordinate, and the second is the y coordinate of the point. It should then plot a least squares regression line on top of the points.
You may assume that all valid points have x-coordinates in the range [0, 40] and y-coordinates in the range [1, 20]. The least-squares line is calculated using the following formula:

Your program should be able to deal with errors in the data file (by catching NumberFormatException when converting text to integers). Ignore lines containing invalid data or points with coordinates out of range, but do not stop reading the file. For example, given the input file:
20 10 0 1 40 20 13 17 13 12 10 ? the x coordinates represent time 15 0 10 20
lines 6 to 8 would be ignored, but the last point would be plotted.
Your program should plot the points using text (for example, with "X"s representing the points, "-"s the regression line segments, and "*"s where a line segment and a point are located at the same spot). You can either display the output on the screen, or write it to an output file; the data file above would produce the following output:
| X ---X | --- | --- | X --- | --- | --- | --- | ---- | -*- | --- | --- X | --- |--- | | | | | | |X +-----------------------------------------
Use a two-dimensional array of characters to store the plot.
Your program should print two scatterplots, using the input files a3plot1.txt and a3plot2.txt.
a3plot1.txt
1 1 2 2 3 2 4 1 5 2 6 3 7 5 8 4 9 3 10 2 11 6 12 5 12 10 13 3 14 4 15 2 16 8 17 7 18 5 19 4 19 9 20 9 21 12 22 11 23 10 24 11 25 15 26 16 27 12 28 14 29 17 30 15 31 16 32 14 33 16 34 18 35 20 36 19 37 12 37 17 38 16 39 20 40 18
a3plot2.txt
20 10 0 1 40 20 13 17 13 12 10 ? the x coordinates represent time 15 0 10 20
19 2 30 3 13 5 38 18 30 20 18 12 25 12 end of file.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
