• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help with program  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I need help with an assignment and am stuck at this one part. I really need help fast. If you could email me at [deleted] that would be great I'm new to this and don't know exactly how this works! thanks!
 
Sheriff
Posts: 22846
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, Mattie! But sorry, that isn't how it works here. Read the FAQ entry HowToAskQuestionsOnJavaRanch. The points on that page which particularly refer to your post are EaseUp and UseTheForumNotEmail and TellTheDetails and UseAMeaningfulSubjectLine.

So anyway, go ahead and describe your problem here. That would be the best way to get answers.
 
Mattie Row
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh okay thanks!

I have to create a histogram class and a test driver. I have the test driver done I think. But the class is where I am stuck. The constructor of the class accepts a positive integer parameter max. The "friendly" application can than submit a sequence of numbers within the range 1 to max by repeatedly using the submit method. The toString method returns a sideways "histogram" representing the submitted numbers.

I have the constructor of th class done. But the submit part is giving me the trouble.
 
Sheriff
Posts: 21137
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like an int[] could be used to store the occurrences. Someone submits a number X, you update the number of occurrences of X. An int[max + 1] would suffice, with element 0 being ignored so indexes 1 to max (inclusive) are valid.
 
Mattie Row
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so like this is what i have so far:


so do i put in sequence[max+1] in the submit method?
 
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I added code tags to your post, making it MUCH easier to read.
 
Rob Spoor
Sheriff
Posts: 21137
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mattie Row wrote:so like this is what i have so far:

Looks pretty good so far.

so do i put in sequence[max+1] in the submit method?

What are the minimum and maximum indexes in the sequence array? In other words, what are the values for x you can safely use in sequence[x] without getting an ArrayIndexOutOfBoundsException?
 
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mattie Row wrote:so like this is what i have so far:


so do i put in sequence[max+1] in the submit method?
No. You have sequence as a field in your class, so it is accessible to all members of your class. And Rob said new int[max + 1], so that is what you need. When you enter a number, you want to count it. So a value in your array has to be incremented. That is the idea of the submit method.

You are reminded that array[40] is the 41st element in that array, and its 1st element is called array[0].
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!