Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 219
  • Last Modified:

urgent-map-pls help

This program takes the number of years and iterations to be runned. It then calculates the scores and stores them in the 2 dimensional score array based on the number of iterations and years.

For example,if the program is runned five times(iterations=3 and years=2), this could be the output.

score[year][iteration]

               Iterations 1   Iteratons 2   Iterations 3
Years   1  2.666667       2.66667         2.66667  
Years  2   3.2224           3.2221          3.4

so what i need to do is to find the percentage for the range based on years
For example, for year 1 , how many times got value between 2.6 to 2.7

For example, for year 2,how many times, got value between 3.2 to 3.3, 3.3 to 3.4

I just realized that the map below takes all the value in and does not consider it based on years..Is there a way to make the map think in years.


 
Map <Double,Integer> map=new HashMap<Double,Integer>();

for(int i=0;years+1;i++)
{
for(int j=0;j<iterations;j++){
Integer val=map.get(score[i][j]);
if(val==null)
map.put(score[i][j],1);

else
{
int newVal=val+1;
map.put(score[i][j],newVal);
}
}
}
0
Jasbir21
Asked:
Jasbir21
  • 4
  • 3
1 Solution
 
objectsCommented:
use 2 maps, one for year 1 and the other for year 2.
If there could be even more years then use a list of maps
0
 
Jasbir21Author Commented:
how do implement the map in lists...


i tried like array..i get array..is there any example ,i could follow ... Map <Double,Integer> map[i]=new HashMap<Double,Integer>();


0
 
Jasbir21Author Commented:
sorry typo....i try like array..i get error...maybe, i not implementing right...is there any example to follow..thank you
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
objectsCommented:
List<Map <Double,Integer>> maps= new ArrayList<Map <Double,Integer>>();
0
 
Jasbir21Author Commented:
I get error ambigious...

I hope, it is ok if put ArrayList in front instead of List..When i compile,it is ok...

ArrayList<Map <Double,Integer>> maps= new ArrayList<Map <Double,Integer>>(years+1);
0
 
Jasbir21Author Commented:
Thanks a lot for the help :-)
0
 
objectsCommented:
yes thats fine :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now