Write a complete Java program that draws a scatterplot by re
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:
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:
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 :
a3plot2.txt:
Solution
// Returns count of possible paths to reach cell at row number m and column
// number n from the topmost leftmost cell (cell at 1, 1)
int numberOfPaths(int m, int n)
{
// Create a 2D table to store results of subproblems
int count[m][n];
// Count of paths to reach any cell in first column is 1
for (int i = 0; i < m; i++)
count[i][0] = 1;
// Count of paths to reach any cell in first column is 1
for (int j = 0; j < n; j++)
count[0][j] = 1;
// Calculate count of paths for other cells in bottom-up manner using
// the recursive solution
for (int i = 1; i < m; i++)
{
for (int j = 1; j < n; j++)
// By uncommenting the last part the code calculatest he total
// possible paths if the diagonal Movements are allowed
count[i][j] = count[i-1][j] + count[i][j-1]; //+ count[i-1][j-1];
}
return count[m-1][n-1];
}
// Driver program to test above functions
int main()
{
cout << numberOfPaths(3, 3);
return 0;
}

