• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Methods and Arrays Help

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Start with the setSales method:


What does final mean?
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
. . . and welcome to the Ranch
 
Karen Wen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you allocate and assign anything for sales?

 
Karen Wen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
My favorite is a chocolate cupcake with white frosting and tiny ad sprinkles.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic