Question
I need to define the ItemFsvoritesListMTF class which uses Java's ArrayList as underlying storage. I wrote my code which its output is different from the
I need to define the ItemFsvoritesListMTF class which uses Java's ArrayList as underlying storage. I wrote my code which its output is different from the output it should be. Please see below. Which part of my code needs to be modified?
Here is my c..;@Override
protectedvoidmoveUp(Item
intindex=list.indexOf(t)-1;
if(t!=list.get(0))
list.addFirst(list.remove(list.indexOf(t)));
}
/**Returnsaniterablecollectionofthekmostfrequentlyaccessedelements.*/
@Override
publicIterable
if(k<0||k>size())
thrownewIllegalArgumentException("Invalidk");
ArrayList
for(Item
temp.addLast(iter.next().getValue());
returnresult;
}
protectedstaticvoidtest(ItemFavoritesList
char[]sample="hello.thisisatestoffavoriteslistmtf".toCharArray();
for(charc:sample){
fav.access(c);
intk=Math.min(5,fav.size());
System.out.println("Entirelist:"+fav);
System.out.println("Top"+k+":"+fav.getFavorites(k));
System.out.println();
}
}
//testusage
publicstaticvoidmain(String[]args){
test(newItemFavoritesListMTF
}
}
Here is output of my code which error occurs:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method addFirst(ItemFavoritesList.Item
at ItemFavoritesListMTF.moveUp(ItemFavoritesListMTF.java:36)
at ItemFavoritesList.access(ItemFavoritesList.java:77)
at ItemFavoritesListMTF.test(ItemFavoritesListMTF.java:56)
at ItemFavoritesListMTF.main(ItemFavoritesListMTF.java:66)
Here is the output which it should be like:
Entire list: [(h:1)]
Top 1: [h]
Entire list: [(e:1), (h:1)]
Top 2: [e, h]
Entire list: [(l:1), (e:1), (h:1)]
Top 3: [l, e, h]
Entire list: [(l:2), (e:1), (h:1)]
Top 3: [l, e, h]
Entire list: [(o:1), (l:2), (e:1), (h:1)]
Top 4: [l, o, e, h]
Entire list: [(.:1), (o:1), (l:2), (e:1), (h:1)]
Top 5: [l, ., o, e, h]
Entire list: [( :1), (.:1), (o:1), (l:2), (e:1), (h:1)]
Top 5: [l,, ., o, e]
Entire list: [(t:1), ( :1), (.:1), (o:1), (l:2), (e:1), (h:1)]
Top 5: [l, t,, ., o]
Entire list: [(h:2), (t:1), ( :1), (.:1), (o:1), (l:2), (e:1)]
Top 5: [h, l, t,, .]
Entire list: [(i:1), (h:2), (t:1), ( :1), (.:1), (o:1), (l:2), (e:1)]
Top 5: [h, l, i, t,]
Entire list: [(s:1), (i:1), (h:2), (t:1), ( :1), (.:1), (o:1), (l:2), (e:1)]
Top 5: [h, l, s, i, t]
Entire list: [( :2), (s:1), (i:1), (h:2), (t:1), (.:1), (o:1), (l:2), (e:1)]
Top 5: [ , h, l, s, i]
Entire list: [(i:2), ( :2), (s:1), (h:2), (t:1), (.:1), (o:1), (l:2), (e:1)]
Top 5: [i,, h, l, s]
Entire list: [(s:2), (i:2), ( :2), (h:2), (t:1), (.:1), (o:1), (l:2), (e:1)]
Top 5: [s, i,, h, l]
Entire list: [( :3), (s:2), (i:2), (h:2), (t:1), (.:1), (o:1), (l:2), (e:1)]
Top 5: [ , s, i, h, l]
Entire list: [(a:1), ( :3), (s:2), (i:2), (h:2), (t:1), (.:1), (o:1), (l:2), (e:1)]
Top 5: [ , s, i, h, l]
Entire list: [( :4), (a:1), (s:2), (i:2), (h:2), (t:1), (.:1), (o:1), (l:2), (e:1)]
Top 5: [ , s, i, h, l]
Entire list: [(t:2), ( :4), (a:1), (s:2), (i:2), (h:2), (.:1), (o:1), (l:2), (e:1)]
Top 5: [ , t, s, i, h]
Entire list: [(e:2), (t:2), ( :4), (a:1), (s:2), (i:2), (h:2), (.:1), (o:1), (l:2)]
Top 5: [ , e, t, s, i]
Entire list: [(s:3), (e:2), (t:2), ( :4), (a:1), (i:2), (h:2), (.:1), (o:1), (l:2)]
Top 5: [ , s, e, t, i]
Entire list: [(t:3), (s:3), (e:2), ( :4), (a:1), (i:2), (h:2), (.:1), (o:1), (l:2)]
Top 5: [ , t, s, e, i]
Entire list: [( :5), (t:3), (s:3), (e:2), (a:1), (i:2), (h:2), (.:1), (o:1), (l:2)]
Top 5: [ , t, s, e, i]
Entire list: [(o:2), ( :5), (t:3), (s:3), (e:2), (a:1), (i:2), (h:2), (.:1), (l:2)]
Top 5: [ , t, s, o, e]
Entire list: [(f:1), (o:2), ( :5), (t:3), (s:3), (e:2), (a:1), (i:2), (h:2), (.:1), (l:2)]
Top 5: [ , t, s, o, e]
Entire list: [( :6), (f:1), (o:2), (t:3), (s:3), (e:2), (a:1), (i:2), (h:2), (.:1), (l:2)]
Top 5: [ , t, s, o, e]
Entire list: [(f:2), ( :6), (o:2), (t:3), (s:3), (e:2), (a:1), (i:2), (h:2), (.:1), (l:2)]
Top 5: [ , t, s, f, o]
Entire list: [(a:2), (f:2), ( :6), (o:2), (t:3), (s:3), (e:2), (i:2), (h:2), (.:1), (l:2)]
Top 5: [ , t, s, a, f]
Entire list: [(v:1), (a:2), (f:2), ( :6), (o:2), (t:3), (s:3), (e:2), (i:2), (h:2), (.:1), (l:2)]
Top 5: [ , t, s, a, f]
Entire list: [(o:3), (v:1), (a:2), (f:2), ( :6), (t:3), (s:3), (e:2), (i:2), (h:2), (.:1), (l:2)]
Top 5: [ , o, t, s, a]
Entire list: [(r:1), (o:3), (v:1), (a:2), (f:2), ( :6), (t:3), (s:3), (e:2), (i:2), (h:2), (.:1), (l:2)]
Top 5: [ , o, t, s, a]
Entire list: [(i:3), (r:1), (o:3), (v:1), (a:2), (f:2), ( :6), (t:3), (s:3), (e:2), (h:2), (.:1), (l:2)]
Top 5: [ , i, o, t, s]
Entire list: [(t:4), (i:3), (r:1), (o:3), (v:1), (a:2), (f:2), ( :6), (s:3), (e:2), (h:2), (.:1), (l:2)]
Top 5: [ , t, i, o, s]
Entire list: [(e:3), (t:4), (i:3), (r:1), (o:3), (v:1), (a:2), (f:2), ( :6), (s:3), (h:2), (.:1), (l:2)]
Top 5: [ , t, e, i, o]
Entire list: [(s:4), (e:3), (t:4), (i:3), (r:1), (o:3), (v:1), (a:2), (f:2), ( :6), (h:2), (.:1), (l:2)]
Top 5: [ , s, t, e, i]
Entire list: [( :7), (s:4), (e:3), (t:4), (i:3), (r:1), (o:3), (v:1), (a:2), (f:2), (h:2), (.:1), (l:2)]
Top 5: [ , s, t, e, i]
Entire list: [(l:3), ( :7), (s:4), (e:3), (t:4), (i:3), (r:1), (o:3), (v:1), (a:2), (f:2), (h:2), (.:1)]
Top 5: [ , s, t, l, e]
Entire list: [(i:4), (l:3), ( :7), (s:4), (e:3), (t:4), (r:1), (o:3), (v:1), (a:2), (f:2), (h:2), (.:1)]
Top 5: [ , i, s, t, l]
Entire list: [(s:5), (i:4), (l:3), ( :7), (e:3), (t:4), (r:1), (o:3), (v:1), (a:2), (f:2), (h:2), (.:1)]
Top 5: [ , s, i, t, l]
Entire list: [(t:5), (s:5), (i:4), (l:3), ( :7), (e:3), (r:1), (o:3), (v:1), (a:2), (f:2), (h:2), (.:1)]
Top 5: [ , t, s, i, l]
Entire list: [( :8), (t:5), (s:5), (i:4), (l:3), (e:3), (r:1), (o:3), (v:1), (a:2), (f:2), (h:2), (.:1)]
Top 5: [ , t, s, i, l]
Entire list: [(m:1), ( :8), (t:5), (s:5), (i:4), (l:3), (e:3), (r:1), (o:3), (v:1), (a:2), (f:2), (h:2), (.:1)]
Top 5: [ , t, s, i, l]
Entire list: [(t:6), (m:1), ( :8), (s:5), (i:4), (l:3), (e:3), (r:1), (o:3), (v:1), (a:2), (f:2), (h:2), (.:1)]
Top 5: [ , t, s, i, l]
Entire list: [(f:3), (t:6), (m:1), ( :8), (s:5), (i:4), (l:3), (e:3), (r:1), (o:3), (v:1), (a:2), (h:2), (.:1)]
Top 5: [ , t, s, i, f]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started