Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7813591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:55:32+00:00 2026-06-02T04:55:32+00:00

Sorry if my title is confusing. I have an assignment due that has to

  • 0

Sorry if my title is confusing.
I have an assignment due that has to do with Java. The goal of the assignment is to create a program that will read an input file of provinces and cities and store the data into a 2D array, one for provinces and one for cities (no duplicates). After that, itt will output it in alphabetic order. If that is confusing here is a sample of what it is supposed to look like.

Sample Input File

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 File

 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

Here is my Main class

import java.io.IOException;

public class Main {

    public static void main(String[] args) throws IOException {
        if (args.length < 2) {
            System.err.println("Usage: java -jar lab5.jar infile outfile");
            System.exit(99);
        }

        Munge dataSorter = new Munge(args[0], args[1]);

        dataSorter.openFiles();
        dataSorter.readRecords();
        dataSorter.writeRecords();
        dataSorter.closeFiles();
    }
}

An here is my Munge class as of now.

import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Formatter;
import java.util.Scanner;

public class Munge {

    private String inputFileName, outputFileName;
    private Scanner inputFile;
    private Formatter outputFile;
    private int line = 0;
    private String[] data;

    public Munge(String inFileName, String outFileName) {
        this.inputFileName = inFileName;
        this.outputFileName = outFileName;

        data = new String[100];
    }

    public void openFiles() throws FileNotFoundException {
    File newFile = new File(inputFileName);
    }

    public void readRecords() {
        while (inputFile.hasNext()) {
            data[line] = inputFile.nextLine();
            System.out.println(data[line]);
            line++;
        }
    }

    public void writeRecords() {
        for (int i = 0; i < line; i++) {
            String done[] = data[i].split(", ");
            Arrays.sort(done);

            for (int j = 0; j < done.length; j++) {
            outputFile.format("%s\r\n", done[j]);
            }
        }
    }

    public void closeFiles() {
        if (inputFile != null) {
            inputFile.close();
        }

        if (outputFile != null) {
            outputFile.close();
        }
    }
}

My problem is mainly happening when I try to run the program. I keep getting The message that is only suppose to occur when args.length < 2. Why is that so & how can I fix this? Do I set args[0] and args[1] to equal files?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T04:55:34+00:00Added an answer on June 2, 2026 at 4:55 am

    You either don’t provide the two filename arguments when you run the program or provide only one of them. For example:

    java -jar lab5.jar infile
    

    will set only the first argument (to the string “infile”), the second one is missing

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry about that confusing title :) I have a resource, ComatosePage (used in the
Sorry the title isn't more help. I have a database of media-file URLs that
Sorry if the title is confusing. I have several string expressions in an array
Sorry for the title may seem confusing. i have 2 element. with no relation
Hello everybody and sorry for the rather confusing question-title. I have a Hibernate Class
Sorry if the title is confusing. Here is the query I have Select MONTH(DATE(TIMESTAMP)),
I'm sorry for the little confusing title but say I have a class with
Sorry for title, I have an interop problem. The C dll that I'm using
sorry for the confusing title. I have two tables, individu and orgcont . individu
Sorry if the title sounds confusing - but this is what I am trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.