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

:Above is snipshot of csv file public class Hill { int number; String name; Stri

ID: 3823464 • Letter: #

Question

:Above is snipshot of csv file

public class Hill {

   int number;
   String name;
   String CountyName;
   double height;
   double latitude,longitude;
   Hill(int n,String name,String cname,double h,double lat,double longitude)
   {
       this.number=n;
       this.name=name;
       CountyName=cname;
       height=h;
       latitude=lat;
       this.longitude=longitude;
   }
}

Above is snapshot of csv file public class Hill {int number; String name; String CountyName; double height; double latitude, longitude; Hill(int n, String name, String cname, double h, double lat, double longitude) {this.number = n; this.name = name; CountyName = cname; height = h; latitude = lat; this.longitude = longitude;}} In class Hill, write a method public static List readHills() The method should read the hill data from file hills.csv. For each row, it should create a corresponding Hill object. The method should return a list containing these objects in the same order as they are in the file. In class Exercise5, create a method: This method should invoke readHills () and display the first 20 list elements on the console. Add an invocation of exercise5b() in the main() method and test your program.

Explanation / Answer

PROGRAM CODE:

package util;

import java.io.File;

import java.io.FileNotFoundException;

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

public class Hill {

int number;

String name;

String CountyName;

double height;

double latitude,longitude;

Hill(int n,String name,String cname,double h,double lat,double longitude)

{

this.number=n;

this.name=name;

CountyName=cname;

height=h;

latitude=lat;

this.longitude=longitude;

}

  

public static List<Hill> readHills()

{

   List<Hill> hills = new ArrayList<>();

   try {

           Scanner reader = new Scanner(new File("hills.csv"));

           String line = reader.nextLine();

           String tokens[] = line.split(",");

           Hill hill = new Hill(Integer.valueOf(tokens[0]), tokens[1], tokens[2], Double.valueOf(tokens[3]), Double.valueOf(tokens[4]), Double.valueOf(tokens[5]));

           hills.add(hill);

       } catch (FileNotFoundException e) {

           // TODO Auto-generated catch block

           e.printStackTrace();

       }

   return hills;

}

  

public static void exercise5b()

{

   List<Hill> listOfHills = readHills();

   for(int i=0; i<listOfHills.size()||i<20; i++)

   {

       System.out.print(listOfHills.get(i).number + " " + listOfHills.get(i).name + " " + listOfHills.get(i).CountyName);

       System.out.println(listOfHills.get(i).height + " " + listOfHills.get(i).latitude + " " + listOfHills.get(i).longitude);

   }

}

  

public static void main(String args[])

{

   exercise5b();

}

}

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