Norway Oslo Northern_Europe 1 480000
Italy Rome Western_Europe 2 2700000
Austria Vienna Central_Europe 4 1600000
Poland Warsaw Central_Europe 4 1660000
Sweden Stockholm Northern_Europe 1 720000
This is what is being asked from my professor:
"1. Build Array of Country Objects. Using input file, you are to build an array of objects. You are to design and develop a class named Country (in addition to your class named Main) and create the number of objects of type (class) Country - one object for each record (line) from the input file. You need to use Buffered Reader, etc. as found (examples on Brief Introduction to Input/Output slide 7)) on my web page. Do not use Scanner.
Each Country object will have five properties defined individually as integers or Strings as appropriate for each Country object attribute. You should download this file and use this as input to your program to create the array of Country objects."
This is my code I have written already to pull the information as a whole from the text file.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package project1barry;
import java.io.*;
/**
*
* @author Jason
*/
public class Country {
private String path;
public Country (String file_path) {
path=file_path;
}
public String [] OpenFile () throws IOException {
FileReader fr = new FileReader (path);
BufferedReader textReader = new BufferedReader (fr);
int numberOfLines = readLines ();
String[ ] textData = new String[numberOfLines];
int i;
for (i=0; i < numberOfLines; i++) {
textData[i] =textReader.readLine();
}
textReader.close();
return textData;
}
int readLines() throws IOException {
FileReader file_to_read = new FileReader (path);
BufferedReader bf = new BufferedReader (file_to_read);
String aLine;
int numberOfLines = 0;
while ((aLine= bf.readLine()) != null) {
numberOfLines++;
}
bf.close();
return numberOfLines;
}
}
Any direction will be appreciated. Thank you in advanced.
This post has been edited by AllHighway: 08 June 2012 - 04:49 PM

New Topic/Question
Reply




MultiQuote








|