[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

interactive java

Posted on 2006-04-19
4
Medium Priority
?
293 Views
Last Modified: 2010-04-17
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
Comment
Question by:RamsTheDon
  • 2
4 Comments
 

Author Comment

by:RamsTheDon
ID: 16493954
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
 
LVL 23

Accepted Solution

by:
brettmjohnson earned 150 total points
ID: 16494225
>          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
 
LVL 6

Assisted Solution

by:_iskywalker_
_iskywalker_ earned 600 total points
ID: 16495871
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
 

Author Comment

by:RamsTheDon
ID: 16498212
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

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question