Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

My code reads in data like this: city name,x,y Calgary 367 661 Edmonton 375 625 ... How would I alter the code so that it

My code reads in data like this:

city name,x,y

Calgary 367 661

Edmonton 375 625

...

How would I alter the code so that it reads in date such as:

city name,x,y Calgary 367 661 Edmonton 375 625 ...

import java.io.*;

public class Program {

private int cityCount; private City cityArray[]; private CompressedArray array; public Program(String fileName, boolean showMap) throws IOException { File file = new File(fileName); FileReader fr = new FileReader(file); BufferedReader br = new BufferedReader(fr); StringBuffer sb = new StringBuffer(); String line; int i = 0; while((line = br.readLine())!=null) { //Has to be changed so that it reads in values that are on different lines String ar[] = line.split(" "); City arr = new City(ar[0], Integer.parseInt(ar[1]), Integer.parseInt(ar[2])); cityArray[i++] = arr; } fr.close(); }

public City[] getCityArray() { return cityArray; } public void expandCapacity() { City temp[] = cityArray; City cityArray[] = new City[temp.length+3]; for(int i = 0; i < temp.length; i++) cityArray[i] = temp[i]; } public double distBetweenCities(City x,City y) { double dis = Math.sqrt((y.getY() - x.getY()) * (y.getY() - x.getY()) + (y.getX() - x.getX()) * (y.getX() - x.getX())); return dis; } public void compareDistances() { double arr[][]=new double[cityArray.length][cityArray.length]; for (int i = 0; i < arr.length; i++) { for(int j = 0; j < arr[i].length; j++) { arr[i][j] = distBetweenCities(cityArray[i], cityArray[j]); } } } public CompressedArray getArray() { return array; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Administration The Essential Reference

Authors: Brian Laskey, David Kreines

1st Edition

1565925165, 978-1565925168

More Books

Students also viewed these Databases questions

Question

=+1 Is the decision fair to employees?

Answered: 1 week ago