Description
Q: Please name your file as YourLastNameQZ1.java, e.g., vatturiQZ1.java
Input file: qz1Data.csv
Assumption: There are less than 10,000 records in qz1Data.csv
The data file “qz1Data.csv” is a csv (comma separate value) file and contains 3 fields, separated by commas, on each line:
Property ID, County, Price
Listed below are some sample lines:
119736,CLAY COUNTY,792148.9
448094,CLAY COUNTY,1438163.57
206893,CLAY COUNTY,192476.78
333743,CLAY COUNTY,86854.48
172534,CLAY COUNTY,246144.49
You are required to:
1. Design and develop a data class for the input data record. Please name the data class as MyRecord. (This class does not need to a public class.) 2. Develop a Java program to read input data records into an object array of MyReccord and display the CPU time used to for such a reading operation.
Hint: This program generates 1 line of output.
.........................................................................................................................................
Ans:
import java.io.*;
import java.util.*;
public class vatturiQZ1
{
public static void main(String []args)
{
int count=0;
long CPU_time=0, end_time=0, start_time=0;
String csvRecord;
ArrayList <MyRecord> recs = new ArrayList <MyRecord> ();
try {
BufferedReader brFile = new BufferedReader(new FileReader("qz1Data.csv"));
start_time = System.currentTimeMillis();
while ((csvRecord = brFile.readLine()) != null)
{
recs.add(new MyRecord(csvRecord));
}
end_time = System.currentTimeMillis();
brFile.close();
}
catch (Exception e) { e.printStackTrace(); };
CPU_time = end_time - start_time;
System.out.print("CPU time used: " + CPU_time + " ms");
}
}
class MyRecord
{
String propertyID;
String county;
double price;
public MyRecord(String myrec)
{
StringTokenizer st = new StringTokenizer(myrec, ",");
propertyID = st.nextToken(",");
county = st.nextToken(",");
price = Double.valueOf(st.nextToken(","));
}
public String getPropertyID() { return propertyID; }
public String getCounty() { return county; }
public double getPrice() { return price; }
..............................................................................................................................
professor's comment:
You did not know your name?!?!?! Your solution has nothing to do with the requirement.
Only 1 student who has completed Quiz#1 with a correct answer.
The question requires you to use an array.
Please redo and resubmit your solution by the new deadline.
Explanation & Answer
Ok, i've added some co...
Review
Review
24/7 Homework Help
Stuck on a homework question? Our verified tutors can answer all questions, from basic math to advanced rocket science!
Similar Content
Related Tags
The President is Missing
by James Patterson, Bill Clinton
The Turn of the Screw
by Henry James
Faust
by Johann Wolfgang von Goethe
The Curious Case of the Dog in the Night Time
by Mark Haddon
The Remains Of The Day
by Kazuo Ishiguro
Shattered - Inside Hillary Clintons Doomed Campaign
by Amie Parnes and Jonathan Allen
East of Eden
by John Steinback
The Two Towers
by J. R. R. Tolkien