• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 297
  • Last Modified:

interactive java

Guys i'm back again. I know this might sound a bit daft on my part but forgive i'm still a novice.
I've done the hard part of the question but i'm stuttering on the construction of a class that will enable users to enter towns in the command prompt and all details for that particular town pop up.
I've done the following , and forgive i've changed the codes so many times because i'm constantly getting errors and hence it looks a bit messy, someone fresh needs to have a look.
Just to remind the format for each town is eg NAMMOTH:NM:280520:-10550:440:464
Nammoth being the town, NM(county code),280520 lat,10550 lon, 440km (east coord) and 464km (north coord).
please feel free to ask me further ? , if u don't understand my ?, i can hardly understand it myself.

THANK YOU

import java.io.*;
public class Distances
{
      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));

                 
        
            {
            
                  int town_name;      
                  if line = town_name. = (NAMMOTH)               {
                       System.out.println("Town Found");
                }
                         
           }
           catch( IOException e )
           {
            System.err.println("IO Exception");
            System.exit(1);

           }      
        }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
}            

0
RamsTheDon
Asked:
RamsTheDon
  • 2
2 Solutions
 
RamsTheDonAuthor Commented:
sorry the more structred prg is as:
import java.io.*;
public class cities
 {
      public static void main(String[] args)
        {

          try
          {
            FileReader file=new FileReader("towns.txt");
            BufferedReader buffer=new BufferedReader(file);
      
            int town_name;
            String town = "NAMMOTH:NM:280520:-10550:440:464";      
            if line==town_name.=(NAMMOTH)
              {
            System.out.println("Town Found");
              }
                try
                {
                    while((textline = buffer.readLine()) !=null)
                  System.out.println(textline);
                  buffer.close();

           
                
             }
             catch( IOException e )
             {
                  System.err.println("IO Exception");
                  System.exit(1);
            }
          catch(FileNotFoundException fnex)
          {
            System.out.println("Couldn't find file");
            System.out.println(":" + fnex.getMessage());
            System.exit(1);
                }      
       }
}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
            
0
 
brettmjohnsonCommented:
>          if line==town_name.=(NAMMOTH)

That does not even approximate legal Java syntax.
What is it that you are actually trying to test?
(Just use english words to describe the condition.)


You should also consider using a programmer's text editor that
automatically indents the code and balances braces, brackets, and
parenthesis.  That would certainly help with the readability of your
code.  An editor with syntax coloring would also help you identify
grossly incorrect syntax (such as your if statement).
0
 
_iskywalker_Commented:
and what is line?
is it the read line?
You didnt also define what is the textline. You should parse one line at time since, it is
the smallest complete piece of information that you have:
String  textline =NULL;
while((textline = buffer.readLine()) !=null){
               System.out.println(textline);
               ParsedInformations muh=parseInformation(textfile);
if(compareInformation(muh, searchingTown)){
printInformation(muh);
}
}
This isnt good indented, but you see creating objects for you strings maybe is a better way of structuring your code. Creating functions working on that objects would be the next step for making a good fileparser. There are still some nice functions for parsing, so look for them also!
0
 
RamsTheDonAuthor Commented:
Thanks guys i'll try all your suggested solutions.
I'll give more feedback in a bit, but please let me know if you've got any addditions to make to the above comments.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now