• Post Reply Bookmark Topic Watch Topic
  • New Topic

Counting help please  RSS feed

 
Michael Pickens
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello. I am working on an assignment which asks me to write a java program that counts the numbers of A's, B's, C's, D's, and F's in an array of 20 randomly generated integers between 1 and 100 inclusively. I am supposed to use separate methods to fill OR display the array, also a separate method to count the letter grades.

The assignment asks for a GUI dialog box to obtain user input for the amount of numbers to randomize and fill into the array.

The only part that his hanging me up is getting the counts right. It seems to count in aggregate of all the numbers...

I understand that the problem is that my counts are not stopping, meaning when I am asking it to count it does, but does not stop once it reaches the threshold to move to the next tier. I have tried reversing the parameters, making it so array[i] <= the max number in the parameter.

I also tried to add some && statements, but it kept telling me that boolean statements and int statements couldn't go into the same line (or i am just not smart enough for that.

Here is an example of a few lines of code that is trying to count from 80-89... but it counts from 80 -... well i dont know where it stops really



thanks for the help.
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The condition in your code (if (arrayThree[i] >= 80)) is actually evaluated to true for any number greater than or equal to 80. If you need to count numbers in the range from 80 to 89, you must modify the condition to also check whether the number is less than or equal 89. You'd use the 'logical and' operator to do that. If you're unsure on how to do it, please see the tutorial.

If this does not help, please post the contents of your array, the output of your program you expect (and why do you expect it) and the output you actually get. We can work from that point on.
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Pickens wrote:
I also tried to add some && statements


where did you try to add the && statements?
 
Michael Pickens
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help.

I added the && here.



but eclipse gave me an error

so I guess my next question is then, how do I define the operator && to fit the argument type?
 
Michael Pickens
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it.. as I typed my last reply... bad mistake on my part.

thanks
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cool. I find so many answers as I'm typing the question.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!