Reading file line by line

[b][red]This message was edited by BabaTT at 2006-4-27 3:7:28[/red][/b][hr]
I've just started java programming and i need assistance with my programme. The programme should calculate distance, time, speed etc.
I've come up with the following programme but i'm still getting error messages, i obviously have got the codes wrong somewhere but i've been cracking my head for the past few days without any solution.
Please someone have a look and tell me where i'm gettin' lost


Comments

  • : I've just started java programming and i need assistance with my programme. The programme should calculate distance, time, speed etc.
    : I've come up with the following programme but i'm still getting error messages, i obviously have got the codes wrong somewhere but i've been cracking my head for the past few days without any solution.
    : Please someone have a look and tell me where i'm gettin' lost
    :
    : import java.io.*;
    :
    : public class towns
    : {
    :
    : // //
    :
    : public static void main (String[] args) {
    : FileReadTest t = new FileReadTest();
    : t.readMyFile();
    : }
    :
    :
    : // //
    :
    : void readMyFile() {
    :
    : String record = null;
    : int recCount = 0;
    :
    : try {
    :
    : FileReader fr = new FileReader("towns.txt");
    : BufferedReader br = new BufferedReader(fr);
    :
    : record = new String();
    : while ((record = br.readLine()) != null) {
    :
    : System.out.println("Town name is " + record);
    : }
    :
    : } catch (IOException e) {
    : // catch possible io errors from readLine()
    : System.out.println("Uh oh, got an IOException error!");
    : e.printStackTrace();
    : }
    :
    : }
    : }// Main class
    : class Towns
    : {
    : private Arraylist towns;
    : public static void main(String[] args) {
    : try {
    : BufferedReader in = new BufferedReader(new FileReader("towns.txt"));
    : String str;
    : while ((str = in.readLine()) != null) {
    : towns.add(new Town(str));
    : }
    : in.close();
    : } catch (IOException e) {
    : }
    : }
    : }
    :
    :
    : // Town class, in Towns.java
    : class Town {
    : // Members
    : private String name;
    : private float lat;
    : private float lon;
    : private float e_coord;
    : private float n_coord;
    : private String county;
    :
    : // Constructors
    : Town(String info) {
    : String[] f = info.split(":");
    : // Put in code for converting types.
    : }
    : // Define accessors and mutators
    : String getName() { return name; }
    : String getCounty() { return county; }
    : float getLat() { return lat; }
    : float getLon() { return lon; }
    : float getECoord() { return e_coord; }
    : float getnNCoord() { return n_coord; }
    :
    : // Methods
    : Distance =Math.sqrt((Math.pow((grid east 1 grid east 2),2) + Math.pow((grid north 1 grid north 2),2))) ;
    :
    : {
    : // Computes distance to another town
    : // Put implementation here
    : }
    :
    : // boolean equals(Town t) {
    : // Compare towns
    : }
    :
    : boolean equals(String n) {
    : // Compare towns by name
    : }
    : //
    : }
    :
    :
    :
    What kind of errors? Compiler errors or run-time errors? And in which method?
  • [b][red]This message was edited by BabaTT at 2006-4-27 3:5:36[/red][/b][hr]
    : : I've just started java programming and i need assistance with my programme. The programme should calculate distance, time, speed etc.
    : : I've come up with the following programme but i'm still getting error messages, i obviously have got the codes wrong somewhere but i've been cracking my head for the past few days without any solution.
    : : Please someone have a look and tell me where i'm gettin' lost
    :
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories