Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

a3plot1.txt a3plot2.txt PART B: SCATTERPLOT Write a complete Java program that d

ID: 3915558 • Letter: A

Question


a3plot1.txt
a3plot2.txt
PART B: 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 valild points have x-coordinates in the range 10. 40) and y coordinates in the range 1. 20) The least- squares line is calculated using the following formulaT ( is the mean of the x values and yis the mean of the y vabues) Your program should be able to deal with errors in the data file (by catching Numberf ormatException when converting ot integers) Ignore lines containing invalid data or points with coordinates out of range, but do not stop reading the file. For converting text to example, given the input file 20 10 o 1 40 20 13 17 13 12 10 2 the x coordinates represent time 15 0 10 20

Explanation / Answer

Answer:

Here, I have following java program as shown below,

Code:

import java.awt.*;

import java.io.*;

import java.util.StringTokenizer;

// implement a class

public class hallo{

    // main function

public static void main(String[] args){

// to get file

GetsFromFile("points.txt");

}

// method to define

public static void GetsFromFile(String fname)

{

// read file

BufferedReader inputFile;

String line;

// create array pointer

int[][] points;

try

{

inputFile = new BufferedReader(new FileReader(fname));

line = inputFile.readLine();

while(line!= null){

points = ReadsThePoint(inputFile,line);

DisplayPoints(points);

line = inputFile.readLine();

}

inputFile.close();

}

catch (IOException | ArrayIndexOutOfBoundsException ioe){

System.out.println(ioe.getMessage());

}

}

// method to read points

public static int[][] ReadsThePoint(BufferedReader inFile, String lines) throws IOException{

String[] splits;

String ILine;

int[][] pts;

int pSize = 9;

pts = new int[pSize][pSize];

for(int row=0; row<pSize;row++){

ILine = inFile.readLine();

System.out.println(inFile);

splits = ILine.split("\s+");

for(int col =0; col <pSize;col++){

pts[row][col] = Integer.parseInt(splits[col]);

}

}

return pts;

}

// method to print the points

public static void DisplayPoints(int[][] pts) {

    // using loop

        for (int ROW=0; ROW < pts.length; ROW++)

        {

            for (int COL=0; COL < pts[ROW].length; COL++)

            {  

                System.out.print(pts[ROW][COL] +" ");

            }

            System.out.println();

        }

    }

}