• 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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Array or ArrayaList

Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, I am having trouble as I am not sure how array or ArrayList work I have a program which I have coded already that show student grade now I would like to show the grade from an array or ArrayList.

What I am trying to do is the numeric rages of grade should be stored in array or ArrayList which is read-only they should not be modifiable the output should be coming out to be same as above code I am having really hard time doing that.
Saloon Keeper
Posts: 9560
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First off, I'd put the conversion to a letter grade into its own method.
Then to use that with an array or array list  is simple with an extended for loop.
Posts: 76419
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Did you notice that Carey didn't use && anywhere? That avoids the problem you would get if somebody enters 93.995 as a grade. It is also less error‑prone; each number you write and each >= you write constitutes an opportunity to get something wrong.
There are exam grades and there are parcel prices. The difference is that the boundary values fit into the lower category and the upper category respectively. If you get 70% in an exam that gets you the same grade as 71% and a higher grade than for 69% because the boundary value counts as part of the upper range. If your parcel weighs 1000g, you pay the same as for 999g and less than you would pay for 1001g. Parcel boundary values count as the lower weight range. Parcel boundary values count as the lower weight range. So in the case of an exam you are interested in whether the mark is less than 70 an for a parcel you want to know whether the weight is more than 1000. So you would writeorThe Unicode escapes are “” <br /> If you are using < go from small to large and if you are using > go from large to small:-...or...In order to accept 100% you can use <=, unless you have a special mark only for people who get 100%. Or you throw the error earlier, moving the > 100 test towards the start of the block of ifs.I ike to use < and > only, if possible, because I think they are less likely to be read wrongly than <= and >=. Try to avoid writing if (1_000.0 > weight) because that is easy to misread.

You might do better not to use a for loop for counting grades like that. A for loop is principally intended for counter controlled repetition and you are not counting anything in your loop. You are looking for a sentinel value (0.0) so you are using sentinel controlled repetition an a different kind of loop would be more appropriate. There is also a serious logic error in your line 16.

I presume Carey guessed correctly what you meant about putting your grades into a List. You cannot put anything in to an array and make it unmodifiable; all arrays are implicitly modifiable. You can get an unmodifiable List like this:-Linke about List#of(). If you are unfamiliar with Lists, you might do well to avoid them for the time being.
Without deviation from the norm, progress is not possible - Zappa. Tiny ad:
Garden Master Course kickstarter
    Bookmark Topic Watch Topic
  • New Topic