4 Replies - 290 Views - Last Post: 06 May 2019 - 12:10 PM Rate Topic: -----

#1 GypsyKing   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-May 19

Reading a file and using different classes

Posted 05 May 2019 - 12:11 PM

Hi,

I'm new here. I'm taking a java course and I have an assignment that I need help with. I don't think I need help with any code but just an understanding of what is going on.

My assignment requires that I read a file in a class named WordApp. When the file is read I have to do various functions with the words of the file. The methods to execute those functions are saved in two different classes that are saved separately. One executes functions on individual words and the other on the file words as a whole. My question is how do I pass the file contents to the methods in the other classes? The caveat is I have to basic java functions so no Map or HashMap. I can use strings and ArrayLists.

If need I can post snippets of code. I just need the understanding of how java is passing the information.

Please explain like I'm 5. :stupid:/> I've searched reading files and count words everything I found has all the methods in one class. Thanks :bigsmile:/>

Is This A Good Question/Topic? 0
  • +

Replies To: Reading a file and using different classes

#2 g00se   User is online

  • D.I.C Lover
  • member icon

Reputation: 3632
  • View blog
  • Posts: 16,679
  • Joined: 20-September 08

Re: Reading a file and using different classes

Posted 05 May 2019 - 12:51 PM

Quote

My question is how do I pass the file contents to the methods in the other classes?


As a String?
Was This Post Helpful? 0
  • +
  • -

#3 GypsyKing   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-May 19

Re: Reading a file and using different classes

Posted 05 May 2019 - 01:04 PM

View Postg00se, on 05 May 2019 - 12:51 PM, said:

Quote

My question is how do I pass the file contents to the methods in the other classes?


As a String?


Yes. I have a string "initial" and this is how I have it written.

    			while(scan.hasNext())
    			{
					initial = scan.next();
				}


Then I pass it
WordProcessor x = new WordProcessor();
				x.addWord(initial);


WordProccessor has a constructor that create an ArrayList of my class WordType

public class WordProcessor
{
	private ArrayList<WordType> words;
	private int totSentences;
	private int totUnique;

	public WordProcessor()
	{
		words = new ArrayList<WordType>();
		totSentences = 0;
		totUnique = 0;
	}


I hope this makes sense
Was This Post Helpful? 0
  • +
  • -

#4 wseng92   User is offline

  • D.I.C Addict
  • member icon

Reputation: 43
  • View blog
  • Posts: 631
  • Joined: 23-September 15

Re: Reading a file and using different classes

Posted 05 May 2019 - 07:52 PM

Have you succcessfully read the file ?
Was This Post Helpful? 0
  • +
  • -

#5 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2853
  • View blog
  • Posts: 11,185
  • Joined: 03-December 12

Re: Reading a file and using different classes

Posted 06 May 2019 - 12:10 PM

View PostGypsyKing, on 05 May 2019 - 02:11 PM, said:

I just need the understanding of how java is passing the information.


Is the question really how Java passed the information, or how you should move data to different classes?

Quote

One executes functions on individual words and the other on the file words as a whole.

So, the question comes in at, what data does the class need to do it thing? What does each class need? Do both classes need the entire file so it can parse it individually? What is the minimum amount of data it needs to work, properly?

For instance,
The user needs to get an accurate count of all words in a file.
Pretty obvious that it needs all the words to be able to do this.

The User wants to capitalize all words that start with 'w'.
Well, you only need to send words fitting that criteria then. So, every word doesn't need to be sent.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1