This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Methods and Arrays Help

 
Karen Wen
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I've been stuck and completely lost on my Java class program since yesterday and I cannot seem to figure out how to resolve these issues since these are just the beginning parts of the program. Can someone guide/hint to me what I need? I will be putting up the parts where I'm stuck at and giving some general information.

I have two classes, SalesStats and Divisions.

In SalesStats class, I have a main that creates a Division object. I'm not sure what the arrays are suppose to be.

I am to read a file and store the data into two dimensional arrays with a method called readValues(Divisions d). This method is to store the file into array d.
The file input is like this:
1234
2345
3456
4567
12345
23456
34567
45678
etc...

I need to set this up so that the arrays will read as 6 rows (divisions) and 4 columns (quarters).

Output will be:
Division1:
1234
2345
3456
4567
Division2:
12345
23456
34567
45678
etc..

Here is the method I'm stuck at:


In Divisions class I'm having trouble with setting div and qrt.


Sorry if this is confusing, I will try to clear the problem more if there's a question.
Thank you!
 
Steve Luke
Bartender
Pie
Posts: 4181
21
IntelliJ IDE Java Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start with the setSales method:


What does final mean?
 
Campbell Ritchie
Sheriff
Pie
Posts: 47262
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and welcome to the Ranch
 
Karen Wen
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi and thank you! I have resolved my issues above, but now when I execute, I get a NullPointerException. Can someone guide me to what I need to do?



Codes in Divisions:


Codes in SalesStats:
 
Gary Ba
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you allocate and assign anything for sales?

 
Karen Wen
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gary Ba wrote:Did you allocate and assign anything for sales?



I don't think I did. Am I suppose to? How/where do I put it? I'm suppose to import a text file that stores the text into arrays as said on my first post.

Edit:
Ok, I've initially assigned sales. When executed, it's all 0.0 and not the numbers I need. Here are parts of the program. What am I doing wrong?



 
Campbell Ritchie
Sheriff
Pie
Posts: 47262
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You appear to be assigning amount to what is in sales for a particular square. Since you haven't done anything with sales yet, that will be 0. I suspect you want your assignment the other way round.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47262
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have final ints, declare sales as new double[DIVISIONS][QUARTERS] rather than using 6 and 4. If you have the numbers, you might as well use them, and that style reduces the risk of errors like entering 5 by mistake.
Also, since you are assigning sales in the setSales method, you will create a new array every time you run that method and lose all you old information. Similarly for your getSales method. You want to create sales in a constructor, I think.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic