• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need some constructive comments  RSS feed

 
Greenhorn
Posts: 8
Chrome Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody, I have a requirement as part of my project where in I am getting a list of integers.The integers are divided into three groups i.e, HIGH(>=80),MEDIUN(<80 && >=20) and LOW(<20).Out of the list I need to pick one integer, but I also need to go through below conditions:

1. If there is just one score of HIGH, we pick this integer as output.
2. If there is more than one score of HIGH, we say an exception has occurred.
3. If there is no score of HIGH, but one score of MEDIUM we pick this integer as output.
4. If there is no score of HIGH, and more than one score of MEDIUM, we say an exception has occurred.
5. If there is no score of HIGH or MEDIUM,but one score of LOW we pick this integer as output.
6. If there is no score of HIGH or MEDIUM,and more than one score of LOW, we say an exception has occurred.

PRORITY: HIGH <-- MEDIUM <-- LOW

I have coded the above requirement as shown below. Guys can you please analyse and share your comments on what improvements can be added to the below code snippet. The code is working as per the requirements.

/*
* Below "scorelist" is the list of scores we are getting as input."hCount/mCount/lCount" are integers used to keep track of which is the only one integer
* found within the three groups."intSelected" gives us the exact score that qualifies the above requirement.
*/

 
Ranch Hand
Posts: 146
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The variable names may be confusing.  For example hCount and highCount look a lot the same.  How about changing the names to  saveHigh vs hCount, etc?
 
Saloon Keeper
Posts: 3330
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Your above 'if's could be simplified to this. Only one of these cases can be true.
 
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!