Question: Hello, I have some Java code that I need to convert the CSV file into the array I have built. I have it being read

Hello,

I have some Java code that I need to convert the CSV file into the array I have built. I have it being read successfully right now but I need it to be converted and cannot quite get it to work. A good portion of it I have built here that I will link, I just require help regarding turning the CSV file into my array (which is located in main.java) and the search by name function(which is located in Array.java). Appreciate any assistance.

main.java

import java.util.Scanner;

import java.io.IOException;

import java.io.File;

import java.io.FileNotFoundException;

import java.io.*;

import java.util.*;

public class main

{

public static void main(String args[]) // beginning of program

{

String fileName = "cities.csv";

File file = new File(fileName);

int console = 0; // initialize console to zero

Array arr = new Array();

try

{

Scanner inputStream = new Scanner(file);

while(inputStream.hasNext())

{

String data = inputStream.next();

System.out.println(data + "***");

}

inputStream.close();

}catch(FileNotFoundException noFile)

{

noFile.printStackTrace();

} // end of try

System.out.println("1. Insert 2. Delete by name 3. Delete by coords 4. Search by name"

+ " 5. Search by coords 6. Print within given dist"

+ " 7. Print all 8. Exit"); // set up the initial menu

Scanner scan = new Scanner(System.in);

while (console != 8)

{ // beginning of while

System.out.println("Please enter 1-8 ");

console = Integer.parseInt(scan.nextLine());

switch (console)

{ // beginning of switch statement

case 1:

System.out.println("Insert Function");

System.out.print(" Enter the City Name: ");

String cityName = scan.nextLine();

System.out.print(" Enter the x coordinate: ");

int x = Integer.parseInt(scan.nextLine());

System.out.print("Enter the y coordinate");

int y = Integer.parseInt(scan.nextLine());

arr.insert(cityName,x,y);

break;

case 2:

System.out.println("Delete by Name function");

break;

case 3:

System.out.println("Delete by coords function");

break;

case 4:

System.out.println("Type in the City Name you wish to find :");

System.out.println("Enter the City name you wish to search for: ");

cityName = scan.nextLine();

arr.searchByName(cityName);

break;

case 5:

System.out.println("Search by Coords function");

break;

case 6:

System.out.println("Print within given district of given point function");

break;

case 7:

System.out.println("Print all function");

break;

case 8:

System.out.println("Exit");

} // end of switch statement and menu

} // end of while statement

System.out.println("did i break out");

}

}

------------------------------

Data.java

import java.util.Scanner;

public class Data

{

public String cityName;

public int x;

public int y;

public Data()

{

}

public Data(String cityName, int x, int y)

{

this.cityName = cityName;

this.x = x;

this.y = y;

}

public String getCity()

{

return cityName;

}

public void setCity(String cityName)

{

this.cityName = cityName;

}

public int getX()

{

return x;

}

public void setX(int x)

{

this.x = x;

}

public int getY()

{

return y;

}

public void setY(int y)

{

this.y = y;

}

}

--------------------------------

Array.java

import java.util.Scanner;

import java.io.BufferedReader;

import java.io.FileReader;

public class Array

{

private Array arr[] = new Array[100];

private int i;

public Array()

{

i = 0;

}

public void insert(String cityName, int x, int y)

{

for(i=0; i

{

}

}

public void deleteByName(String cityName)

{

}

public void deleteByCoord(int x, int y)

{

}

public void searchByName(String cityName)

{

String cityKey = cityName;

for(i=0; i

{

if (cityKey == cityName)

{

System.out.println(" City was found within the array");

break;

}

else

{

System.out.println("City not found in the Array");

break;

}

}

}

public void searchByCoord(int x, int y)

{

}

public void print()

{

}

public void printAll()

{

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!