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

here is the assignment. You will write a program to read a Comma Separated Value

ID: 3547570 • Letter: H

Question

here is the assignment.

You will write a program to read a Comma Separated Value (.csv) file into an ArrayList of Rectangles. A sample file is in the Canvas Files/Test Files area.  Its name is 00-Rectangle-TestData.csv


The file is composed of lines, each of which corresponds to a rectangle. The first number on each line represents the x location of the upper-left-hand corner of the rectangle. The second number is the y location. The third and fourth numbers represent the width and height of the rectangle, respectively.
You will create a class, Rectangle, that has four int fields: x, y, width, and height.


The class will have the following methods:

Explanation / Answer

/********************** week09.java **********************/

package rectangle;


import java.io.BufferedReader;

import java.io.File;

import java.io.FileReader;

import java.io.IOException;

import java.util.ArrayList;

import java.util.StringTokenizer;


public class week09 {


/**

* @param args the command line arguments

*/

public static void main(String[] args) throws IOException {

File file = new File("inp.csv");

ArrayList<Rectangle> list = new ArrayList<Rectangle> ();

BufferedReader fileReader = new BufferedReader(new FileReader(file));

String line;

while ((line = fileReader.readLine()) != null){

StringTokenizer tokenizer = new StringTokenizer(line, ",");

String x = tokenizer.nextToken();

String y = tokenizer.nextToken();

String width = tokenizer.nextToken();

String height = tokenizer.nextToken();

Rectangle r = new Rectangle(Integer.parseInt(x),Integer.parseInt(y),Integer.parseInt(height),Integer.parseInt(width));

list.add(r);

}

  

double min = 100000;

Rectangle m = null,n = null;

for(Rectangle r : list) {

for(Rectangle s: list) {

double d = r.distance(s);

if(d < min) {

min = d;

m = r; n = s;

}

}

}

  

System.out.println("Minimum Area Rectangles:");

System.out.println(m.toString());

System.out.println(n.toString());

  

System.out.println("Equal Rectancles:");

for(Rectangle r : list) {

for(Rectangle s: list) {

if(r.equals(s))

System.out.println(r.toString() + " " + s.toString());

}

}

}

}