Forums Register Login

Need some constructive comments

1
+Pie Number of slices to send: Send
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.
*/

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send

Your above 'if's could be simplified to this. Only one of these cases can be true.
 
Water! People swim in water! Even tiny ads swim in water:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 274 times.
Similar Threads
Tree Data Structure
Tree Data Structure
Exceptions
String issue in Java code
Problem with order of output
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 04:55:49.