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 6694721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:08:05+00:00 2026-05-26T06:08:05+00:00

I am working on a problem and I am very stuck because I am

  • 0

I am working on a problem and I am very stuck because I am just starting to learn java. Any help I can get to understand this would be great. I have to write a program that has two classes. The main class will read from a file and uses the second class to find how may times the same words have been repeated in the file and add them to an array that contans the words and number of times the word repeated. I am ok with the reading the file part. I just can’t seem to wrap my head around how to call a method from the second class to add the word into the array and increment the counter.
Here is my code so far if you run it you will see how new I am to this by how many errors you will get.

import java.io.*;

public class Words{
public static void main (String [] args)
{
    ProcessInput();
    System.out.println("\nprogram finished");
}


public static WordList ProcessInput( )
{
    BufferedReader inputFile;
    String inputLine;
    String[] word;
    WordList words;
        try
        {
            inputFile=new BufferedReader(new FileReader ("inputFile.txt"));
            inputLine = inputFile.readLine();
            while (inputLine !=null)
            {
                word=inputLine.toLowerCase().split(" ");
                for (int i=0; i<word.length; i++){
                    System.out.println (word[i]);
                    words=addWord(word[i]);
                }
                inputLine = inputFile.readLine();

            }
            inputFile.close();
        }
        catch (IOException ioe)
        {
            System.out.println (ioe.getMessage());
            ioe.printStackTrace ();
        }
        return words;
}

}

class WordList {
String [] words;
int wordcount;
public WordList ( ){
    words= new String [1000];
    wordcount=0;

}

public String  addWord (String word) {
    words[wordcount]=word;
    wordcount=+1;
    return words[wordcount];

}

public void printList (){
    for (int i=0; i<wordcount; i++){
        System.out.println (words[i]);
    }
}
}
  • 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-05-26T06:08:06+00:00Added an answer on May 26, 2026 at 6:08 am

    You’re very close. What you need to remember is when you’re calling a method from another class you need to tell the compiler where to find that method.

    So, instead of simply calling addWord("someWord"), you will need to initialise an instance of the WordList class (e.g. WordList list = new WordList();), and then call the method using that (i.e. list.addWord("someWord");.

    However, your code at the moment will still throw an error there, because that would be trying to call a non-static method from a static one. So, you could either make addWord() static, or change the methods in the Words class so that they’re not static.

    My bad with the above paragraph – however you might want to reconsider ProcessInput() being a static method – does it really need to be?

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

Sidebar

Related Questions

Very odd problem as this is working perfectly on our old Classic ASP site.
I am semi-frustrated with this Yii CGridView problem and any help or guidance would
I am working in MATLAB and I'm stuck on a very simple problem: I've
This is a very trivial problem but I can't seem to find a way
I'm stuck on a RegEx problem that's seemingly very simple and yet I can't
I am really stuck with this problem. Page I'm working on is here the
I'm working on a problem that requires caching paginated search results: Paginating very large
I have a layout that is working, but it has one very annoying problem..
I had a problem working with the image classes in java. I am creating
I am working on a problem and got stuck at a wall I have

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.