Question
Asked by:
cpr4cpu
cpr4cpu
Rating : No Rating
Questions Asked: 3
Tutorials Posted: 2, earned $3.00
 

$10.00 Java - read text from an input file and write to new output file based on values

Q:
Develop an application that reads city, state, and population from an input text file.

Example census input text file should be of the format:

Jamestown FL 50000
Domville CO 10000
Jennyboro FL 30000
Lillyville CO 50000

City should be the first field, state abbreviation should be the second field, and the population (no commas) should be the third field. White spaces (no commas) should be used as the delimiter between each field and a platform independent line separator should be used at the end of each city record. This file will be used as input to a future application which is why the format is important.

If the population of the city is greater than or equal to 50,000 write the city information to a text file called BigCities.txt. If the population of the city is less than 50,000 write the city information to a text file called SmallCities.txt.

If your output file(s) already exist, you should append to it, not overwrite.

Explain which input and output stream classes used and your reasons for your choice.

Before you write any Java code, start with planning comments also known as pseudocode. These comments will serve as the outline of your logic for each method including your test application. The comments should be left in your code and part of your grade will come from these comments.


 


   
   
   
   
 
Available Tutorials to this Question
Posted by:
Neel
Neel
Rating (237): C
Questions Asked: 0
Tutorials Posted: 1637, earned $2,000.41
 

$10.00 Java - read text from an input file and write to new output file based on values

  • This tutorial was purchased 1 time and hasn't been rated yet.
  • Posted on Jul. 13, 2009 at 10:21:26AM
A:
Preview: ... Hello stude ...

The full tutorial is about 8 words long plus attachments.

Attachments:
BigCities.txt (0K) (Preview)
Cities.txt (0K) (Preview)
City.java (1K) (Preview)
SmallCities.txt (0K) (Preview)
Posted by:
modulo51
modulo51
Rating (110): A-
Questions Asked: 1
Tutorials Posted: 353, earned $2,117.64
 

$10.00 Java, read, sort, write to files, Scanner to read, PrintWriter to wrtie,NetBeans project foldeer, ScreenShot, UseNotes

  • This tutorial was purchased 4 times and rated A+ by students like you.
  • Posted on Jul. 14, 2009 at 01:26:56AM
A:
Preview: ... int count = 0;<br> // keep reading until file is exhausted:<br> while (inStream.hasNext()) {<br> count++;<br> line = inStream.nextLine();<br> System.out.print(" " + count + ") " + line);<br><br> // break line into compnent substrings around spaces:<br> part = line.split(" ");<br><br> // population is the third element of the line:<br> double population = Double.parseDouble(part[2]);<br><br> // sort into big or little output files:<br> if (population >= 50000) {<br> System.out.println(" ---> " + bigOutFileName);<br> bigOutStream.println(line);<br><br> } else {<br> System.out.println(" --> " + smallOutFileName);<br> ...

The full tutorial is about 1423 words long plus attachments.

Attachments:
CensusSort.java (4K) (Preview)
CensusSortScreenShot.JPG (50K) (Preview)
CensusSortUseNotes.txt (3K) (Preview)
CensusSortZipped.zip (58K)
   
Join Now or Log In
Get Tutoring
Get Paid
Academic Honesty