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

Assumption: Thenumber of records in hw4Data.csvis unknownThe data file “hw4Data.

ID: 3731635 • Letter: A

Question

Assumption: Thenumber of records in hw4Data.csvis unknownThe data file “hw4Data.csv” is a csv (comma separate value) file and contains 3 fields, separated by commas, on each line:Property ID, County, PriceListed below are some sample lines:119736,CLAY COUNTY,792148.9448094,CLAY COUNTY,1438163.57206893,CLAY COUNTY,192476.78333743,CLAY COUNTY,86854.48172534,CLAYCOUNTY,246144.49Please develop a Java program to:1.Read all data records from hw4Data.csvfile into 2 data structures:Binary search treejava.util.LinkedList2.Show the memory used by the binary search tree3.Show the memory used by java.util.LinkedList4.Sort records in descending order by Price(largest first) and display the CPU used for such an operation. Perform these operations on the data structured created in Step 1.Hint: This program generates at most 4lines of output.

Explanation / Answer

CODE:

private int pid;

   private String county;

   private double price;

   //Constructor

   public MyRecord(int pid,

           String county,

           double price) {

       this.pid=pid;

       this.county=county;

       this.price=price;

   }

   //toString method

   public String toString() {

       return String.format("%-10d%-15s%-10f",

               pid,county,price);

   }

   //Start of main method

   public static void main(String[] args) {

       //set a file name

       String fileName="pj2Data.csv";

       //create a variable of type Scanner

       Scanner filereader=null;

       try {

           //create an instnace of Scanner with file name

           filereader=new Scanner(new File(fileName));

           //get time in milliseconds

           long startTime = System.currentTimeMillis();

           while(filereader.hasNextLine())

           {

               //read file

               String line=filereader.nextLine();

               System.out.println(line);

           }

           //get time in milliseconds

           long endTime = System.currentTimeMillis();

           //Get time in seconds

           System.out.println("Seconds take for execution is:"

                   +(endTime-startTime)/1000);

       } catch (Exception e) {

           System.out.println("Error :In File Opening");

       }

       //close the file

       filereader.close();

   }

}

inputs:

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote