• 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

Need help with program

 
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 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!
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I added code tags to your post, making it MUCH easier to read.
 
Rob Spoor
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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].
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic