java - Working with data from table -


i wondering if advice on implementing algorithm creating jfreechart. basically, extracting data jtable contains information patients. there age categories patients such 20-26, 26-30, 31-35, 35-40, 50-55, 55-60 etc. there 30 of them , every patient belongs corresponding age category. there button on top of jtable opens frame containing age distribution graph. thinking of doing:

  1. create integer variable every category
  2. loop through age details patients in jtable
  3. compare variables jtable data , increment 1 if there match (lots of if statements go in loop)
  4. store categories names , amount of people registered under every category in hashmap
  5. pass map chartframe

i suppose might relatively way of doing wondering if possibly suggest way of avoiding having create variable every category , having comparisons using 30 if statements.

edit: not have patient's exact age - category belong to.

i've assumed you've got own class agerange stores range of ages. can store age ranges in treemap<integer,agerange>, key first number of range , value range itself.

when need find age range contains particular age, use

  themap.lowerentry(age + 1) 

to find it.

check treemap javadoc @ http://docs.oracle.com/javase/7/docs/api/java/util/treemap.html


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -