How to nicely extract data from a .csv table and display it ?

Hello there !

I've got 2 csv files on my hand ; the first listing restaurants, with 3 columns(coordinate x, coordinate y, restaurant name) and another listing deliveries (coordinate x, delivery coordinate y , name of the restaurante the delivery was done by).

I need to : 1) Display the number of deliveries made for each restaurant. 2) The average distance of the deliveries for each restaurant (distance being calculated by this formula = sqrt(sq(x1-x2)+sq(y1-y2) at least I figured something out :p)

For the first, I made a class which looks like this :

Then I'm trying to go trought the deliveries table and change the arraylist of objects so that when the string happens to be the same in a row and the arraylist object the object counts gets to +1. But it doesn't seem to work. Any tips appreciated for the step 2, also.


  • edited April 2017

    convention says variables start with small letter, classes with a Capital and constants are all BIG letters.

    The capitals: it's not RSTEASY but Restaurant or RestEasy (class name).

    You can't use == on Strings

    Use .equals("..") instead - see reference

    Now you should define your list of restaurants in setup and use it in draw

    So no new in draw but only in setup

  • Please edit your post, select your code and hit ctrl+o to format your code. Make sure there is an empty line above and below your code.

    For the coordinates, what units are you using? Is it lat/lon for example? If so, you could use unfolding maps. Check the examples provided after you install the library using the library manager. Or you can access the lib's website by googling Processing unfoldingmaps.

    For the distance, there is a dist() function in processing. I will ask you to check the reference:


  • edited April 2017

    I'm having problems with double looping trough the Arraylist and deleting the items correctly now. Any ideas ?

  • Answer ✓


    You should have one list with restaurants and one with deliveries and compare those against each other

    To get the average distance sum the distances and after the loop say avg= sum / count

  • I first need to display the number of deliveries for each restaurant.

  • That's the whole point....

    Do you have restaurants and deliveries both in L1 ???

  • Nah, I've made two different array's and then compared them. My program is fully working now thank you for the tips guys !

Sign In or Register to comment.