This week's book giveaway is in the Spring forum.
We're giving away four copies of Modern frontends with htmx and have Wim Deblauwe on-line!
See this thread for details.
Win a copy of Modern frontends with htmx this week in the Spring forum!
  • 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

I wanted to write a method that would return the year with the most number of hits as part of ex 4.3

 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!
I wanted to write a method that would return the year with the most number of hits as part of ex 4.34 of Objects First With Java third edition.I am not happy how it has come out.I would like your advice.One thing I want to note is the finalCount is initialized to zero.if only intermidiateValue exceeds the finalCount only the maximumCountYear is updated.My point is if intermidiateValue does not exceeds Zero then maximumHourCountYear will not be updated.What I want is to find way of comparing values within the ArrayList without using preset values like zero since it may lead to a wrong out put.I do not know whether I have conveyed the message clearly, I hope you would understand.yearlyCounts is an ArrayList.reader is an object.


From here all the 4 classes are shown





The Log file is attached to execute the programme.






Regards Varuna
 
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


Ask yourself 2 questions:

1) What is the purpose of finalCount? [What are you using it for, and do you need it]
2) When do you really want to assign intermediateCount to maximumCountYear? [be specific, then consider what value might be best to use when deciding to make that assignment or not]
 
Varuna Seneviratna
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In this code there is no point in having finalCount, But what I want is to find a way to use value intermidiateValue derived by counting the number of times an year has come up in the logLine and compare it with another obtained the same way, then from a "if" to update the finalCount and maximumCountYear.What I am saying is usually done at the start of loops.I am asking whether there is a way to do it that way after a loop execution has finished and before the start of the next round of the same loop.

Regards Varuna
 
reply
    Bookmark Topic Watch Topic
  • New Topic