ࡱ> @B?] 5bjbj99 *(S0\S0\5::$$q-,,,,,,,$9/1d--+-UUU,U,UU)4,?s p+,,A-0q-+S2}S2X4,S24,U--7q-S2:> x: COP 2210 Laboratory 11: Introduction to ArrayLists (ArrayLists of Primitive Types) Partner 1 Name and Section: ______________________________________________________ Partner 2 Name and Section: ______________________________________________________ Objectives: To understand the concept of a list index and how to use it to access the individual list items To practice using for statements to "visit" each item on an ArrayList (i.e., traverse a list) To learn to use ArrayList methods size, get, and add To gain experience working with generic ArrayLists of primitive types in this case int Begin by copying this file from the class web page to your src folder: NumberListTester.java Exercise 1: NumberListTester.java Class NumberList implements a simple list of Integers, using an ArrayList. NumberListTester generates 10 random, positive, 2-digit ints, and adds them to the list. It then calls method printList which prints the items on the list. Run the program until you understand what it does. Write the body of the method printReversed, which prints the list items in reverse order. Add a statement in main to call printReversed after the call to printList. Check ______ Write the body of the method printEveryOther, which prints every other item on the list, beginning with the first one. In main, replace the statement that calls printReversed with one that calls printEveryOther. Check ______ Write the body of the method printEvens, which prints all the even-numbered ints on the list. In main, replace the statement that calls printEveryOther with one that calls printEvens. Check ______ All this printing is getting a bit tedious. Let's try some more fun operations. d. 0. Add a new ArrayList-of-integer instance variable called bigList to the NumberList class Add a statement to the NumberList constructor that creates an empty ArrayList object pointed to by bigList Delete the call to printEvens from main. Write the body of the method splitList, which copies all ints that are greater than or equal to 50 from aList to bigList. Add a method to the NumberList class to print bigList. Add a sequence of method calls in main to verify that the splitList method is working correctly. I.e., after calling splitList, call again the method that prints the original list and then call the method you wrote in step 4 to print the bigList. Check _____ Add a method insert to the NumberList class that takes two parameters of type int. The first parameter is the index at which to insert a new number into the list, and the second is the number to be inserted. E.g., if the first param is 4 and the second is 37, then 37 will be inserted at index 4 in aList (i.e., as the new 5th list element). The number inserted does not replace the number currently at that position, but is inserted just before it. Hint: The ArrayList class has a method that does exactly this. Call that method from your insert method. Now add statements to main to allow the user to specify the number to insert and the position at which to insert it. Then, after inserting the new number, print the updated list. Check _____ Finally, add code to your insert method that will assure that an IndexOutOfBoundsException cannot be thrown. I.e., your insert method should just print an appropriate error message if the first parameter --- the index at which to insert the new Integer --- is illegal. Hint: What are the legal indices for an ArrayList? What is the smallest? What is the largest? What about the special case of inserting a new value at the end of the list? Try it! Check _____ +67WZ\   7 <   [ ^ f i   - q u ~ 4 8 [ h } ϼϼϼϼϼ϶ϰϠϠՐϐϼϼϼϼϼϼϼ hh]cCJhh5CJ hCJhLohLo5CJ hLoCJ hjCJ hh]c6CJ hh]c5CJ hh]c5 hh]cCJhh]c huj5CJ h{0 h{0 5CJ h{0 5CJ hA35CJ hh]c5CJ 86Z[\    s  _ ` $a$$ & F @^`a$$ & F @^`a$gdh]c 8^8`$a$ p@ ^`gd{0  p@ ^`   XYf $ & Fa$gdYX$a$gdYX$@^@a$$ & Fa$$a$} (7LWfg| #'()=GWZ^abt{!B h'CJ hYX6CJ hLoCJ hjCJ hu;{CJ h9 6CJ hCJhYXhYX6CJ h9 CJ hYXCJ hOOhCJ hh]cCJ hh]c6CJC)bYZghi/0PQ^_` $@^@a$gd0 $^a$gde$ & F $ 0^`0a$gdYX$ & F ^`a$gdYX $^a$gdOOh$@^@a$$a$ $ & Fa$gdYXBPWXgiv|"9<XYln ./0;D׽׷׭קꜧvh0h06CJhu;{h0CJhjh0CJh=h06CJh0hh]cCJaJ h0CJh0he6CJ h=CJheheCJH*hehe6CJ hMCJ heCJ hh]c6CJ hOOhCJ hh]cCJhYXhYX6CJ hYXCJ.Q_`wz"-mno%'45ſ hh]cCJ hMCJh0h0CJaJ hCJ hf>QCJh=h05CJh=h0CJ hA}4CJ h0CJh=h=6CJ h=CJ heCJ`no&'45$@`@a$ $@^@a$gd=$ & F h0^`0a$gdA}4$ ^`a$gde$ & F ^`a$gdA}4(/ =!"#$% s2 0@P`p2( 0@P`p 0@P`p 0@P`p 0@P`p 0@P`p 0@P`p8XV~ 0@ 0@ 0@ 0@ 0@ 0@ 0@ 0@ 0@ 0@ 0@ 0@ 0@ 0@_HmH nH sH tH 8`8 Normal_HmH sH tH 8@8  Heading 1$@&CJ88  Heading 2$@&CJ>@>  Heading 3$$@&a$CJBB  Heading 4$$@&a$5CJDA D Default Paragraph FontViV  Table Normal :V 44 la (k (No List 0U0 Hyperlink>*B*PK![Content_Types].xmlN0EH-J@%ǎǢ|ș$زULTB l,3;rØJB+$G]7O٭VvnB`2ǃ,!"E3p#9GQd; H xuv 0F[,F᚜K sO'3w #vfSVbsؠyX p5veuw 1z@ l,i!b I jZ2|9L$Z15xl.(zm${d:\@'23œln$^-@^i?D&|#td!6lġB"&63yy@t!HjpU*yeXry3~{s:FXI O5Y[Y!}S˪.7bd|n]671. tn/w/+[t6}PsںsL. J;̊iN $AI)t2 Lmx:(}\-i*xQCJuWl'QyI@ھ m2DBAR4 w¢naQ`ԲɁ W=0#xBdT/.3-F>bYL%׭˓KK 6HhfPQ=h)GBms]_Ԡ'CZѨys v@c])h7Jهic?FS.NP$ e&\Ӏ+I "'%QÕ@c![paAV.9Hd<ӮHVX*%A{Yr Aբ pxSL9":3U5U NC(p%u@;[d`4)]t#9M4W=P5*f̰lk<_X-C wT%Ժ}B% Y,] A̠&oʰŨ; \lc`|,bUvPK! ѐ'theme/theme/_rels/themeManager.xml.relsM 0wooӺ&݈Э5 6?$Q ,.aic21h:qm@RN;d`o7gK(M&$R(.1r'JЊT8V"AȻHu}|$b{P8g/]QAsم(#L[PK-![Content_Types].xmlPK-!֧6 0_rels/.relsPK-!kytheme/theme/themeManager.xmlPK-!R%theme/theme/theme1.xmlPK-! ѐ' theme/theme/_rels/themeManager.xml.relsPK] 5(} B5  `5 8@0(  B S  ?0@hl -~[h}(7LV0:| '=GW^P W  " 775:Y\fi'(t{g i     " 8 8 X Y l n u u  " %'47'(t{g i     " 8 8 X Y l n u u  " %7Y:|82cz)V,$xWk )85,pW" F-pW"SO0 CW+9ڦR\M)8PMZ4PnAQ`WGZT8bztdQb  h;%y@mZJlqp\D3t)8@@^@`.hh^h`o(.h^h`CJOJQJo(w0h^h`5679;<B*CJ8H*OJQJS*TXo(+@@^@`.@@^@`.hh^h`o()0h^h`5679;<B*CJ4H*OJQJS*TXo(+0h^h`5679;<B*CJ8H*OJQJS*TXo(+0h^h`5679;<B*CJ4H*OJQJS*TXo(+ ^`hH.^`o(.8$ $ ^$ `CJ0OJQJaJ0o(hHF @ @ ^@ `hH. ^`hH. L^`LhH. ^`hH. ^`hH. PLP^P`LhH. @ @ ^@ `o(hH. ^`hH. pLp^p`LhH. @ @ ^@ `hH. ^`hH. L^`LhH. ^`hH. ^`hH. PLP^P`LhH.hh^h`CJ OJQJo(lhh^h`CJ OJQJo(lhh^h`o()hh^h`o()0h^h`5679;<B*CJ4H*OJQJS*TXo(+8hh^h`CJ0OJQJaJ0o(hHF8hh^h`OJQJ^Jo(hHo888^8`OJQJo(hH8^`OJQJo(hH8  ^ `OJQJ^Jo(hHo8  ^ `OJQJo(hH8xx^x`OJQJo(hH8HH^H`OJQJ^Jo(hHo8^`OJQJo(hH0h^h`5679;<B*CJ8H*OJQJS*TXo(+QbSO0 h F-5,CW+9PM%y@m)V3t\MWGZY82cxWk T8bAQ4PJlq X*+              +        $#jMYX9 {0 eLo"#+A}40kHjMf>Q_Wbh]cOOhLtu;{X~=bN5eA30 ujc'57@" " " " 5@UnknownG*Ax Times New Roman5Symbol3. *Cx Arial;WingdingsSMonotype SortsSymbol?= *Cx Courier NewA$BCambria Math"1h+'+  4.. 2QHP?_W2!xx COP 2210 Gregory Shaw Greg ShawX              Oh+'0h  $ 0 <HPX` COP 2210Gregory ShawNormal Greg Shaw3Microsoft Office Word@V@^@b ՜.+,0 hp|   .  COP 2210 Title  !"#$%&'()*+,-.012345689:;<=>ARoot Entry FC1Table2WordDocument*(SummaryInformation(/DocumentSummaryInformation87CompObjr  F Microsoft Word 97-2003 Document MSWordDocWord.Document.89q