Please develop a Java program to: 1. Read input records from pj2Data.csv into ja
ID: 3730570 • Letter: P
Question
Please develop a Java program to:
1. Read input records from pj2Data.csv into java.util.ArrayList.
2. Display the CPU time used in Step 1.
3. Display the memory used by java.util.ArrayList.
4. Read input records from pj2Data.csv into java.util.Vector.
5. Display the CPU time used in Step 4.
6. Display the memory used by java.util.Vector.
Name your driver file/class as YourLastName.java
Input file: pj2Data.csv
Assumption: The number of records in pj2Data.csv is unknown
Objective: Compare the Memory efficiency and CPU efficiency between java.util.ArrayList and java.util.Vector.
Hint: This program generates 2 or 4 lines of output.
Getting the memory usage may not be as straight forward as it seems.
o Ava and Eva share a bank account which has $100 in it.
o Ava took out some money, the balance is $60. How much did Ava take out?
$100 - $60 = $40 Hence, Ava took out $40.
o Eva took out some money, the balance is $30. How much did Eva take out?
$100 - $30 = $70 Hence, Eva took out $70.
$40 + $70 = $110 But, the original account balance was $100
Must be in one java file
pj2Data ex:
119736 CLAY COUNTY 792148.9 448094 CLAY COUNTY 1438164 206893 CLAY COUNTY 192476.8 333743 CLAY COUNTY 86854.48 172534 CLAY COUNTY 246144.5 785275 CLAY COUNTY 884419.2 995932 CLAY COUNTY 20610000Explanation / Answer
import java.io.*;
import java.util.*;
class item{
public int field1;
public String field2;
public double field3;
}
public class Demo127{
public static void main(String[] args){
ArrayList<item> arraylist = new ArrayList<item>();
Vector<item> vlist = new Vector<item>(1000);
try {
FileInputStream fin = new FileInputStream("pj2Data.csv");
Scanner sc = new Scanner(fin);
long start = System.currentTimeMillis();
while (sc.hasNextLine()){
String line = sc.nextLine();
String[] list = line.split(",");
item a = new item();
a.field1 = Integer.parseInt(list[0]);
a.field2 = list[1];
a.field3 = Double.parseDouble(list[2]);
arraylist.add(a);
}
sc.close();
fin.close();
long end = System.currentTimeMillis();
System.out.println("Time with ArrayList is "+ (end -start));
FileInputStream fin1 = new FileInputStream("pj2Data.csv");
sc = new Scanner(fin1);
start = System.currentTimeMillis();
while (sc.hasNextLine()){
String line = sc.nextLine();
String[] list = line.split(",");
item a = new item();
a.field1 = Integer.parseInt(list[0]);
a.field2 = list[1];
a.field3 = Double.parseDouble(list[2]);
vlist.addElement(a);
}
sc.close();
fin.close();
end = System.currentTimeMillis();
System.out.println("Time with Vector is "+ (end -start));
}
catch (Exception e){
e.printStackTrace();
}
}
}