954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Assignment

Write a java program that will open a file, read each of the records from the file, use that data to populate a two dimensional array and write the sorted data out to a new text file.
Define a class named Munge which will do all the 'heavy lifting' in this program.
Build your project in NetBeans using the Run - Build Project, or Run - Clean and Build Project menu item.
From the dist directory you will execute your program from the command line with two filenames as arguments, input file name and output file name. For example:
java -jar lab5.jar ..\input.txt ..\output.txt
The input file will be a plain text file with one city name followed by a comma, followed by a single space, followed by the name of the province. The input file will have no more than 15 cities from one province so you can hard-code that value into your program when you are defining the size of your array. Some provinces may not exist in the data. The input file could be empty and your program should still run fine. Hand in all the input files you used to show how your data design helped to thoroughly test your software.
The output file will consist of the name of a province (assuming it has at least one city) followed by a colon, followed by a space a then a list of the cities from that province sorted alphabetically. The list of cities is comma separated. Notice the last city does not have a comma after it.
The provinces are sorted west to east followed by the three territories also from west to east.
The data must be stored in a two dimensional array of java Strings. Index 0 will represent the array of city Strings from British Columbia, index 1 will represent the array of city Strings from Alberta ... index 11 will represent the array of city Strings from Nunavut. By structuring it this way the provinces are already sorted.
When opening the files, catch the following exceptions: FileNotFoundException and SecurityException. Exit the program cleanly with an informative message to the user if these occur.
When reading records from the input file catch a NoSuchElementException and exit your program cleanly with an informative error message if this occurs.
When writing data to the output file catch a FormatterClosedException and exit your program cleanly with an informative error message if this occurs.

sample input
Hamilton, Ontario
Montreal, Quebec
Vancouver, British Columbia
Sarnia, Ontario
Sherbrooke, Quebec
Winnipeg, Manitoba
Red Deer, Alberta
Edmonton, Alberta
Niagara Falls, Ontario
Port Elgin, Ontario
Victoria, British Columbia
Truro, Nova Scotia
Regina, Saskatchewan
Kingston, Ontario
Fredricton, New Brunswick
Grand Prarie, Alberta
Calgary, Alberta
Collingwood, Ontario

sample output
British Columbia: Vancouver, Victoria
Alberta: Calgary, Edmonton, Grand Prarie, Red Deer
Saskatchewan: Regina
Manitoba: Winnipeg
Ontario: Collingwood, Hamilton, Kingston, Niagara Falls, Port Elgin, Sarnia
Quebec: Montreal, Sherbrooke
New Brunswick: Fredricton
Nova Scotia: Truro

learning.java
Newbie Poster
1 post since Apr 2011
Reputation Points: 7
Solved Threads: 0
 

good luck with your homework

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

Finished. What does your's look like?

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

I'm in my first year software development program..
I need help help with this assingment aswell please..
I've spent hours working on it and still can't get it working properly;
Thanks

JavaLearners123
Newbie Poster
6 posts since Apr 2012
Reputation Points: 0
Solved Threads: 0
 

so ... the OP was too lazy to work on it himself, you just hijack this thread and expect us to solve it for you?
and if that's not enough, you then go and copy-paste the assignment to create a new identical thread???

mwa .. mwaaaaa ..

hope you're not expecting high marks on java development this year.

stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: