tag:blogger.com,1999:blog-90007141314149145662024-03-13T00:26:49.286-07:00Binh's BlogBinh Tranhttp://www.blogger.com/profile/06892129796699737316noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-9000714131414914566.post-48506376713247499502010-05-04T17:36:00.000-07:002010-05-04T17:48:42.518-07:00How to Jailbreak your iPhone 3G, 3Gs, ipodTouch, iPad device?Thanks to all the hard work that Dev Team have done, we are finally can perform a safe jailbreak of all apple devices. As we all know, the term "Jailbreak" refers to a third party software that allow user to put more software into their devices. The jailbreaking software called: "Spirit" and it will perform a safe jailbreak for iPhone or ipod Touch, as well as iPad. <div>Note: According to Spirit webpage, your device has to be in normal operating condition, as well as not stuck in the "Recovery screen", or "Touch to call for emergency". So here is the link and another extra link that i posted in, enjoy folks!</div><div><a href="http://spiritjb.com/">http://spiritjb.com/</a></div><div>http://www.4shared.com/file/1NW5RNY2/Spirit.html</div><div><br /></div>Binh Tranhttp://www.blogger.com/profile/06892129796699737316noreply@blogger.com0tag:blogger.com,1999:blog-9000714131414914566.post-72543268729718750152010-03-31T22:30:00.000-07:002010-03-31T22:43:32.878-07:00April 4th... iPad finally coming to the wild world<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEja9MCSWQVJaYSfLXVgrwdsmk_u5E9DG2Gu5wnGN7HstMSjVCcxdZVygNGlIr6wd304TcjPQw6F_H6LVVfAoph21XzJwiLdeOr5dTG6O7ypRYQBiEhClQfLHojAt4bga4dk_OLWcG_XJWk/s1600/packaging_20100127.jpg"><img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 320px; height: 172px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEja9MCSWQVJaYSfLXVgrwdsmk_u5E9DG2Gu5wnGN7HstMSjVCcxdZVygNGlIr6wd304TcjPQw6F_H6LVVfAoph21XzJwiLdeOr5dTG6O7ypRYQBiEhClQfLHojAt4bga4dk_OLWcG_XJWk/s320/packaging_20100127.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5455037516713305410" /></a><br />As Apple announced April 4th ,2010 as the new released day of the mighty iPad(late April for the 3G model with a separate plan), Apple's fan finally find something they have always looking for at a cost of a netbook. A fully touchable multimedia device with the height of 9.56 inches(242.8 mm), Width: 7.47 inches(about 189.7 mm) and it weights around 1.6 pound for the wifi with 3G model, and 1.5 pound for the standard integrated wifi model. Overall, the price seem quite reasonable with a start of $499.00 USD for the base model. This device will give Apple a fresh start as well as a new toy within the entertainment world. As nobody have seen the device yet, more update will be coming soon...<div>Stay tunned :D</div>Binh Tranhttp://www.blogger.com/profile/06892129796699737316noreply@blogger.com0tag:blogger.com,1999:blog-9000714131414914566.post-50342466341536723732010-03-31T22:04:00.000-07:002010-03-31T22:05:46.670-07:00Last Assignment of the year<b><span style="font-family:Times New Roman;font-size:7;color:#9b0000;"><span style="font-family:Times New Roman;font-size:7;color:#9b0000;"><span style="font-family:Times New Roman;font-size:7;color:#9b0000;"> <p align="left">COMP1005 - Assignment #4</p></b></span></span></span><span style="font-family:Times New Roman;font-size:6;color:#00009b;"><span style="font-family:Times New Roman;font-size:6;color:#00009b;"><span style="font-family:Times New Roman;font-size:6;color:#00009b;"><p align="left">Due: </span></span></span></p><span style="font-family:Times New Roman;font-size:6;color:#00009b;"><span style="font-family:Times New Roman;font-size:6;color:#00009b;"><span style="font-family:Times New Roman;font-size:6;color:#00009b;">April </span></span></span><span style="font-family:Times New Roman;font-size:6;color:#00009b;"><span style="font-family:Times New Roman;font-size:6;color:#00009b;"><span style="font-family:Times New Roman;font-size:6;color:#00009b;">1 </span></span></span><p align="left"><b><span style="font-family:Times New Roman;font-size:6;color:#00009b;"><span style="font-family:Times New Roman;font-size:6;color:#00009b;"><span style="font-family:Times New Roman;font-size:6;color:#00009b;">at 1</span></span></span><span style="font-family:Times New Roman;font-size:6;color:#00009b;"><span style="font-family:Times New Roman;font-size:6;color:#00009b;"><span style="font-family:Times New Roman;font-size:6;color:#00009b;">1:55 pm</p></b></span></span></span><span style="font-family:Times New Roman;"><p align="left">In this assignment you will simulate a </span></p><b><span style="font-family:Times New Roman;">Customer </b></span><span style="font-family:Times New Roman;">that goes to a grocery store and buys items. The </span><b><span style="font-family:Times New Roman;">Customer </b></span><p align="left"><span style="font-family:Times New Roman;">will</p><p align="left">select </span></p><b><span style="font-family:Times New Roman;">GroceryItems </b></span><p align="left"><span style="font-family:Times New Roman;">and place them into an ArrayList representing a grocery basket and then when buying the</p><p align="left">items, he will pack them into </span></p><b><span style="font-family:Times New Roman;">GroceryBags </b></span><p align="left"><span style="font-family:Times New Roman;">which will also use ArrayLists. Implement the classes and methods as</p><p align="left">described below.</p></span><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><p align="left">(1) The </span></span></span></p><b><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;">GroceryItem </b></span></span></span><p align="left"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;">Class:</p></span></span></span><span style="font-family:Times New Roman;"><p align="left">Here is a class that represents a </span></p><b><span style="font-family:Times New Roman;">GroceryItem </b></span><p align="left"><span style="font-family:Times New Roman;">that you buy at the grocery store:</p></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">public class </b></span></span></p><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">GroceryItem {</p></span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">private </b></span></span></p><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">String name;</p></span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">private </b></span></span></p><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">float price;</p></span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">private </b></span></span></p><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">float weight;</p></span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">private </b></span></span></p><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">boolean perishable;</p></span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">public </b></span></span></p><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">GroceryItem() { </span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">this</b></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">("", 0, 0, </span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">false</b></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">); }</p></span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">public </b></span></span></p><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">GroceryItem(String n, </span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">float </b></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">p, </span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">float </b></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">w, </span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">boolean </b></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">per) {</p><p align="left">name = n;</p><p align="left">price = p;</p><p align="left">weight = w;</p><p align="left">perishable = per;</p><p align="left">}</p></span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">public </b></span></span></p><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">String getName() { </span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">return </b></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">name; }</p></span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">public float </b></span></span></p><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">getWeight() { </span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">return </b></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">weight; }</p></span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">public float </b></span></span></p><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">getPrice() { </span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">return </b></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">price; }</p></span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">public boolean </b></span></span></p><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">isPerishable() { </span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">return </b></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">perishable; }</p></span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">public </b></span></span></p><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">String toString () {</p></span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">return </b></span></span></p><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">name + </span></span><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;">" weighing " </span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">+ weight + </span></span><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;">" kg with price $" </span></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">+ price;</p><p align="left">}</p><p align="left">}</p></span></span><span style="font-family:Times New Roman;"><p align="left">Complete this class by implementing an </span></p><b><span style="font-family:Times New Roman;">equals() </b></span><span style="font-family:Times New Roman;">method that takes an </span><b><span style="font-family:Times New Roman;">Object </b></span><span style="font-family:Times New Roman;">as a parameter and returns a </span><p align="left"><b><span style="font-family:Times New Roman;">boolean</p></b></span><span style="font-family:Times New Roman;"><p align="left">indicating whether or not two GroceryItems are equal. Note that GroceryItems are only equal if they have the same</p><p align="left">name and weight (note that price doesn't matter). Test your method with the following test program:</p></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">public class </b></span></span></p><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">GroceryItemTestProgram {</p></span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">public static void </b></span></span></p><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">main(String args[]) {</p><p align="left">GroceryItem g1 = </span></span></p><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">new </b></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">GroceryItem(</span></span><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;">"Ocean Spray Cranberry Cocktail"</span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">, 2.99f, 2.26f, </span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">false</b></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">);</p><p align="left">GroceryItem g2 = </span></span></p><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">new </b></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">GroceryItem(</span></span><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;">"Heinz Beans Original"</span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">, 0.79f, 0.477f, </span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">false</b></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">);</p><p align="left">GroceryItem g3 = </span></span></p><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">new </b></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">GroceryItem(</span></span><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;">"Ocean Spray Cranberry Cocktail"</span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">, 1.77f, 2.26f, </span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">false</b></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">);</p><p align="left">System.out.println(g1.equals(g1)); </span></span></p><p align="left"><b><span style="font-family:Courier New;font-size:85%;color:#006500;"><span style="font-family:Courier New;font-size:85%;color:#006500;"><span style="font-family:Courier New;font-size:85%;color:#006500;">// true</p></b></span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">System.out.println(g1.equals(g2)); </span></span></p><p align="left"><b><span style="font-family:Courier New;font-size:85%;color:#006500;"><span style="font-family:Courier New;font-size:85%;color:#006500;"><span style="font-family:Courier New;font-size:85%;color:#006500;">// false</p></b></span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">System.out.println(g1.equals(g3)); </span></span></p><p align="left"><b><span style="font-family:Courier New;font-size:85%;color:#006500;"><span style="font-family:Courier New;font-size:85%;color:#006500;"><span style="font-family:Courier New;font-size:85%;color:#006500;">// true</p></b></span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">}</p><p align="left">}</p></span></span><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><p align="left">(2) The </span></span></span></p><b><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;">GroceryBag </b></span></span></span><p align="left"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;">Class:</p></span></span></span><span style="font-family:Times New Roman;"><p align="left">Implement a class called </span></p><b><span style="font-family:Times New Roman;">GroceryBag </b></span><span style="font-family:Times New Roman;">that represents a bag which will hold </span><p align="left"><b><span style="font-family:Times New Roman;">GroceryItem</p></b></span><span style="font-family:Times New Roman;"><p align="left">objects. The class should have the following </span></p><b><span style="font-family:Times New Roman;">private static </b></span><p align="left"><span style="font-family:Times New Roman;">variable:</p></span><b><span style="font-family:Times New Roman;color:#00009b;"><span style="font-family:Times New Roman;color:#00009b;"><p align="left">MAXWEIGHT = 5; </b></span></span></p><span style="font-family:Times New Roman;">of type </span><b><span style="font-family:Times New Roman;">float </b></span><p align="left"><span style="font-family:Times New Roman;">which indicates the maximum weight that the bag</p><p align="left">can hold (i.e., set to 5 kg)</p><p align="left">The class must have the following </span></p><b><span style="font-family:Times New Roman;">private </b></span><p align="left"><span style="font-family:Times New Roman;">instance variables:</p><p align="left">items which is an </span></p><b><span style="font-family:Times New Roman;">ArrayList<grocerybag> </b></span><span style="font-family:Times New Roman;">that will hold only </span><b><span style="font-family:Times New Roman;">GroceryItem </b></span><p align="left"><span style="font-family:Times New Roman;">objects.</p><p align="left">weight of type </span></p><b><span style="font-family:Times New Roman;">float </b></span><p align="left"><span style="font-family:Times New Roman;">which stores the weight of the bag with its current items.</p><p align="left">Don't forget to </span></p><b><span style="font-family:Times New Roman;">import java.util.ArrayList</b></span><span style="font-family:Times New Roman;">. For the </span><b><span style="font-family:Times New Roman;">GroceryBag </b></span><p align="left"><span style="font-family:Times New Roman;">class, create the following methods:</p><p align="left">Appropriate </span></p><b><span style="font-family:Times New Roman;">public </b></span><p align="left"><span style="font-family:Times New Roman;">get methods</p><p align="left">A zero-parameter constructor.</p><p align="left">A </span></p><b><span style="font-family:Times New Roman;">toString() </b></span><p align="left"><span style="font-family:Times New Roman;">method that displays a string showing the number of items in the bag and the total weight as</p><p align="left">follows: "</span></p><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;">4.3 kg GroceryBag with 8 items</span></span></span><span style="font-family:Times New Roman;">". However, if the bag is empty, this method should return "</span><p align="left"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;">An</p><p align="left">empty GroceryBag</span></span></span></p><p align="left"><span style="font-family:Times New Roman;">".</p><p align="left">A method called </span></p><b><span style="font-family:Times New Roman;">addItem(GroceryItem g) </b></span><span style="font-family:Times New Roman;">which adds the given </span><b><span style="font-family:Times New Roman;">GroceryItem </b></span><p align="left"><span style="font-family:Times New Roman;">to the bag, provided that the</p><p align="left">weight of the item will not cause the bag to exceed the MAXWEIGHT. Make sure to update the total weight</p><p align="left">variable.</p><p align="left">A method called </span></p><b><span style="font-family:Times New Roman;">removeLastItem() </b></span><span style="font-family:Times New Roman;">which removes the </span><b><span style="font-family:Times New Roman;">LAST </b></span><p align="left"><span style="font-family:Times New Roman;">item that was added to the bag. Make sure to</p><p align="left">update the total weight again. If there are no items in the bag, do nothing.</p><p align="left">Test your class with the following test program:</p></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">public class </b></span></span></p><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">GroceryBagTestProgram {</p></span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">public static void </b></span></span></p><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">main(String args[]) {</p><p align="left">GroceryItem g1 = </span></span></p><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">new </b></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">GroceryItem(</span></span><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;">"Jumbo Cherries"</span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">, 6.59f, 1.0f, </span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">false</b></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">);</p><p align="left">GroceryItem g2 = </span></span></p><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">new </b></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">GroceryItem(</span></span><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;">"Smart-Ones Frozen Entrees"</span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">, 1.99f, 0.311f, </span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">true</b></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">);</p><p align="left">GroceryItem g3 = </span></span></p><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">new </b></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">GroceryItem(</span></span><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;">"SnackPack Pudding"</span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">, 0.99f, 0.396f, </span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">false</b></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">);</p><p align="left">GroceryItem g4 = </span></span></p><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">new </b></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">GroceryItem(</span></span><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;">"Nabob Coffee"</span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">, 3.99f, 0.326f, </span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">false</b></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">);</p><p align="left">GroceryItem g5 = </span></span></p><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">new </b></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">GroceryItem(</span></span><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;">"Gold Seal Salmon"</span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">, 1.99f, 0.213f, </span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">false</b></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">);</p><p align="left">GroceryBag b1 = </span></span></p><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">new </b></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">GroceryBag();</p><p align="left">GroceryBag b2 = </span></span></p><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">new </b></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">GroceryBag();</p><p align="left">b1.</span></span></p><b><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;">addItem</b></span></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">(g1);</p><p align="left">b1.</span></span></p><b><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;">addItem</b></span></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">(g2);</p><p align="left">b1.</span></span></p><b><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;">addItem</b></span></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">(g3);</p><p align="left">b1.</span></span></p><b><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;">addItem</b></span></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">(g4);</p><p align="left">b1.</span></span></p><b><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;">addItem</b></span></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">(g5);</p><p align="left">b1.</span></span></p><b><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;">addItem</b></span></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">(g5);</p><p align="left">b1.</span></span></p><b><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;">addItem</b></span></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">(g5);</p><p align="left">System.out.println(b1);</p><p align="left">System.out.println(b2);</p><p align="left">System.out.println(b1.getItems());</p><p align="left">b1.</span></span></p><b><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;">removeLastItem</b></span></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">();</p><p align="left">b1.</span></span></p><b><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;">removeLastItem</b></span></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">();</p><p align="left">b1.</span></span></p><b><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;">removeLastItem</b></span></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">();</p><p align="left">System.out.println(b1);</p><p align="left">System.out.println(b1.getItems());</p><p align="left">b1.</span></span></p><b><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;">addItem</b></span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">(</span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">new </b></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">GroceryItem(</span></span><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;">"Coca-Cola 12-pack"</span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">, 3.49f, 5.112f, </span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">false</b></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">));</p><p align="left">b2.</span></span></p><b><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;">addItem</b></span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">(</span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">new </b></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">GroceryItem(</span></span><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;">"Coca-Cola 12-pack"</span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">, 3.49f, 5.112f, </span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">false</b></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">));</p><p align="left">System.out.println(b1);</p><p align="left">System.out.println(b2);</p><p align="left">}</p><p align="left">}</p></span></span><span style="font-family:Times New Roman;"><p align="left">Here is the output that you should see (the array lists of items will appear on one line though):</p></span><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><p align="left">A 2.6720002 kg GroceryBag with 7 items</p><p align="left">An empty GroceryBag</p><p align="left">[Jumbo Cherries weighing 1.0 kg with price $6.59,</p><p align="left">Smart-Ones Frozen Entrees weighing 0.311 kg with price $1.99,</p><p align="left">SnackPack Pudding weighing 0.396 kg with price $0.99,</p><p align="left">Nabob Coffee weighing 0.326 kg with price $3.99,</p><p align="left">Gold Seal Salmon weighing 0.213 kg with price $1.99,</p><p align="left">Gold Seal Salmon weighing 0.213 kg with price $1.99,</p><p align="left">Gold Seal Salmon weighing 0.213 kg with price $1.99]</p><p align="left">A 2.033 kg GroceryBag with 4 items</p><p align="left">[Jumbo Cherries weighing 1.0 kg with price $6.59,</p><p align="left">Smart-Ones Frozen Entrees weighing 0.311 kg with price $1.99,</p><p align="left">SnackPack Pudding weighing 0.396 kg with price $0.99,</p><p align="left">Nabob Coffee weighing 0.326 kg with price $3.99]</p><p align="left">A 2.033 kg GroceryBag with 4 items</p><p align="left">An empty GroceryBag</p></span></span></span><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><p align="left">(3) The </span></span></span></p><b><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;">Customer </b></span></span></span><p align="left"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;">Class:</p></span></span></span><span style="font-family:Times New Roman;"><p align="left">Implement a class called </span></p><b><span style="font-family:Times New Roman;">Customer </b></span><p align="left"><span style="font-family:Times New Roman;">which represents a person that buys</p><p align="left">grocery items. The </span></p><b><span style="font-family:Times New Roman;">Customer </b></span><p align="left"><span style="font-family:Times New Roman;">should keep the following instance variable:</p><p align="left">shoppingCart which is an </span></p><b><span style="font-family:Times New Roman;">ArrayList<groceryitem> </b></span><p align="left"><span style="font-family:Times New Roman;">of all the</p></span><b><span style="font-family:Times New Roman;"><p align="left">GroceryItem </b></span></p><p align="left"><span style="font-family:Times New Roman;">objects that the customer is planning to purchase.</p><p align="left">Create the following methods.</p></span><b><span style="font-family:Times New Roman;"><p align="left">public </b></span></p><p align="left"><span style="font-family:Times New Roman;">get method for the shopping cart.</p><p align="left">A zero-argument constructor.</p><p align="left">A </span></p><b><span style="font-family:Times New Roman;">toString() </b></span><span style="font-family:Times New Roman;">method that returns a string representation of the customer in the form: "</span><p align="left"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;">Customer with</p><p align="left">shopping cart of 10 items</span></span></span></p><p align="left"><span style="font-family:Times New Roman;">".</p><p align="left">An </span></p><b><span style="font-family:Times New Roman;">addItem(GroceryItem g) </b></span><span style="font-family:Times New Roman;">method that adds a given </span><b><span style="font-family:Times New Roman;">GroceryItem </b></span><p align="left"><span style="font-family:Times New Roman;">to the shopping cart.</p><p align="left">A </span></p><b><span style="font-family:Times New Roman;">removeItem(GroceryItem g) </b></span><span style="font-family:Times New Roman;">method that removes a given </span><b><span style="font-family:Times New Roman;">GroceryItem </b></span><p align="left"><span style="font-family:Times New Roman;">from the shopping cart.</p><p align="left">Create the following 5 interesting </span></p><b><span style="font-family:Times New Roman;">Customer </b></span><p align="left"><span style="font-family:Times New Roman;">methods. A thorough test case is given at the end of this section. Use</p><p align="left">it to test your program as you go by commenting out the parts that you did not complete yet:</p><p align="left">A </span></p><b><span style="font-family:Times New Roman;">heaviestItem() </b></span><p align="left"><span style="font-family:Times New Roman;">method that returns the heaviest item in the shopping cart.</p><p align="left">A </span></p><b><span style="font-family:Times New Roman;">alreadyHave(GrocerytItem g) </b></span><span style="font-family:Times New Roman;">method that takes a </span><b><span style="font-family:Times New Roman;">GroceryItem </b></span><span style="font-family:Times New Roman;">object and returns a </span><b><span style="font-family:Times New Roman;">boolean </b></span><p align="left"><span style="font-family:Times New Roman;">indicating</p><p align="left">whether or not the item is currently in the shopping cart.</p><p align="left">A private </span></p><b><span style="font-family:Times New Roman;">printReceipt() </b></span><p align="left"><span style="font-family:Times New Roman;">method that prints out a receipt for all items in the shopping cart when they are</p><p align="left">purchased. The receipt must be nicely displayed with proper formatting (i.e., everything lined up perfectly).</p><p align="left">It should show the subtotal of all costs, the GST and PST amounts, and finally the Amount Due. Below is</p><p align="left">what it should look like. Note that to align the items as you loop through them, make use of the</p></span><b><span style="font-family:Times New Roman;"><p align="left">String.format() </b></span></p><p align="left"><span style="font-family:Times New Roman;">method which displays strings and floats nicely. For example, the following command</p></span><b><span style="font-family:Courier New;font-size:85%;color:#650000;"><span style="font-family:Courier New;font-size:85%;color:#650000;"><span style="font-family:Courier New;font-size:85%;color:#650000;"><p align="left">String.format("%15s %10.2f", myString, myFloat) </b></span></span></span></p><p align="left"><span style="font-family:Times New Roman;">returns a String object in which the characters from</p></span><b><span style="font-family:Times New Roman;"><p align="left">myString </b></span></p><span style="font-family:Times New Roman;">are displayed (taking up 15 spaces) followed by a space character and then finishing with </span><p align="left"><b><span style="font-family:Times New Roman;">myFloat</p></b></span><span style="font-family:Times New Roman;"><p align="left">value (displayed with 2 decimal places and taking up 10 characters in total). You just need to play around</p><p align="left">with the numbers here to get what you want. Note that the </span></p><b><span style="font-family:Times New Roman;">String.format() </b></span><p align="left"><span style="font-family:Times New Roman;">method simply creates a new</p><p align="left">String...it does not display anything.</p></span><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><p align="left">Smart-Ones Frozen Entrees 1.99</p><p align="left">SnackPack Pudding 0.99</p><p align="left">Breyers Chocolate Icecream 2.99</p><p align="left">Nabob Coffee 3.99</p><p align="left">Gold Seal Salmon 1.99</p><p align="left">Ocean Spray Cranberry Cocktail 2.99</p><p align="left">Heinz Beans Original 0.79</p><p align="left">Lean Ground Beef 4.94</p><p align="left">5-Alive Frozen Juice 0.75</p><p align="left">Coca-Cola 12-pack 3.49</p><p align="left">Smart-Ones Frozen Entrees 1.99</p><p align="left">Ocean Spray Cranberry Cocktail 2.99</p><p align="left">SnackPack Pudding 0.99</p><p align="left">SnackPack Pudding 0.99</p><p align="left">Breyers Chocolate Icecream 2.99</p><p align="left">Breyers Chocolate Icecream 2.99</p><p align="left">Breyers Chocolate Icecream 2.99</p><p align="left">Breyers Chocolate Icecream 2.99</p><p align="left">Breyers Chocolate Icecream 2.99</p><p align="left">Coca-Cola 12-pack 3.49</p><p align="left">Toilet Paper - 48 pack 40.96</p><p align="left">5-Alive Frozen Juice 0.75</p><p align="left">Gold Seal Salmon 1.99</p><p align="left">Ocean Spray Cranberry Cocktail 2.99</p><p align="left">Heinz Beans Original 0.79</p><p align="left">Lean Ground Beef 4.94</p><p align="left">Lean Ground Beef 4.94</p><p align="left">Lean Ground Beef 4.94</p><p align="left">Gold Seal Salmon 1.99</p><p align="left">---------------------------------------</p><p align="left">Subtotal $114.60</p><p align="left">GST $ 5.73</p><p align="left">PST $ 9.17</p><p align="left">---------------------------------------</p><p align="left">Amount Due $129.50</p></span></span></span><span style="font-family:Times New Roman;"><p align="left">A private </span></p><b><span style="font-family:Times New Roman;">packBags() </b></span><span style="font-family:Times New Roman;">method which returns a mixed </span><b><span style="font-family:Times New Roman;">ArrayList </b></span><span style="font-family:Times New Roman;">of packed </span><b><span style="font-family:Times New Roman;">GroceryBag </b></span><p align="left"><span style="font-family:Times New Roman;">objects and possibly</p><p align="left">some unpacked </span></p><b><span style="font-family:Times New Roman;">GroceryItems </b></span><p align="left"><span style="font-family:Times New Roman;">(e.g., case of coke). The method should use the following packing algorithm:</p><p align="left">Fill as many bags as are necessary one at a time, each to just below its weight limit. That is take items in any</p><p align="left">order from the shopping cart and place them into an initially empty bag and stop when the next item will cause</p><p align="left">the bag to exceed its weight limit. Then make a new bag and pack that one until it is full. The items are taken</p><p align="left">sequentially from the basket in any order (although the test code given assumes that you take them in the order</p><p align="left">that they were added to the cart). As each item is packed it should be removed from the shopping cart (use the</p></span><b><span style="font-family:Times New Roman;"><p align="left">removeItem() </b></span></p><p align="left"><span style="font-family:Times New Roman;">method). If an item is too heavy (i.e., exceeds the MAXWEIGHT) to be placed in a bag (e.g., a</p><p align="left">case of coke), then it should be added separately to the </span></p><b><span style="font-family:Times New Roman;">ArrayList </b></span><p align="left"><span style="font-family:Times New Roman;">that is being returned. Hence, the returned</p></span><b><span style="font-family:Times New Roman;"><p align="left">ArrayList </b></span></p><span style="font-family:Times New Roman;">may contain both </span><b><span style="font-family:Times New Roman;">GroceryBag </b></span><span style="font-family:Times New Roman;">and </span><b><span style="font-family:Times New Roman;">GroceryItem </b></span><p align="left"><span style="font-family:Times New Roman;">objects.</p><p align="left">A private </span></p><b><span style="font-family:Times New Roman;">displayPackedBags(ArrayList bags) </b></span><span style="font-family:Times New Roman;">method that takes the result </span><span style="font-family:Times New Roman;">of </span><span style="font-family:Times New Roman;">the </span><b><span style="font-family:Times New Roman;">packBags() </b></span><p align="left"><span style="font-family:Times New Roman;">method (i.e., an</p><p align="left">ArrayList of </span></p><b><span style="font-family:Times New Roman;">GroceryBag </b></span><span style="font-family:Times New Roman;">and unpacked </span><b><span style="font-family:Times New Roman;">GroceryItem </b></span><p align="left"><span style="font-family:Times New Roman;">objects) and displays them nicely as follows. Note the</p><p align="left">2 space indentation for easy readability. There is a minor bug in JCreator that sometimes leaves a blank line</p><p align="left">in the output at weird locations ... do not lose any sleep over this as there is nothing you can do about it ;)</p></span><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><p align="left">GROCERY BAG</p><p align="left">Smart-Ones Frozen Entrees weighing 0.311 kg with price $1.99</p><p align="left">SnackPack Pudding weighing 0.396 kg with price $0.99</p><p align="left">Breyers Chocolate Icecream weighing 2.27 kg with price $2.99</p><p align="left">Nabob Coffee weighing 0.326 kg with price $3.99</p><p align="left">Gold Seal Salmon weighing 0.213 kg with price $1.99</p><p align="left">UNPACKED ITEM</p><p align="left">Coca-Cola 12-pack weighing 5.112 kg with price $3.49</p><p align="left">GROCERY BAG</p><p align="left">Ocean Spray Cranberry Cocktail weighing 2.26 kg with price $2.99</p><p align="left">Heinz Beans Original weighing 0.477 kg with price $0.79</p><p align="left">Lean Ground Beef weighing 0.75 kg with price $4.94</p><p align="left">5-Alive Frozen Juice weighing 0.426 kg with price $0.75</p><p align="left">Smart-Ones Frozen Entrees weighing 0.311 kg with price $1.99</p><p align="left">GROCERY BAG</p><p align="left">Ocean Spray Cranberry Cocktail weighing 2.26 kg with price $2.99</p><p align="left">SnackPack Pudding weighing 0.396 kg with price $0.99</p><p align="left">SnackPack Pudding weighing 0.396 kg with price $0.99</p><p align="left">GROCERY BAG</p><p align="left">Breyers Chocolate Icecream weighing 2.27 kg with price $2.99</p><p align="left">Breyers Chocolate Icecream weighing 2.27 kg with price $2.99</p><p align="left">GROCERY BAG</p><p align="left">Breyers Chocolate Icecream weighing 2.27 kg with price $2.99</p><p align="left">Breyers Chocolate Icecream weighing 2.27 kg with price $2.99</p><p align="left">UNPACKED ITEM</p><p align="left">Coca-Cola 12-pack weighing 5.112 kg with price $3.49</p><p align="left">UNPACKED ITEM</p><p align="left">Toilet Paper - 48 pack weighing 10.89 kg with price $40.96</p><p align="left">GROCERY BAG</p><p align="left">Breyers Chocolate Icecream weighing 2.27 kg with price $2.99</p><p align="left">5-Alive Frozen Juice weighing 0.426 kg with price $0.75</p><p align="left">Gold Seal Salmon weighing 0.213 kg with price $1.99</p><p align="left">GROCERY BAG</p><p align="left">Ocean Spray Cranberry Cocktail weighing 2.26 kg with price $2.99</p><p align="left">Heinz Beans Original weighing 0.477 kg with price $0.79</p><p align="left">Lean Ground Beef weighing 0.75 kg with price $4.94</p><p align="left">Lean Ground Beef weighing 0.75 kg with price $4.94</p><p align="left">Lean Ground Beef weighing 0.75 kg with price $4.94</p><p align="left">GROCERY BAG</p><p align="left">Gold Seal Salmon weighing 0.213 kg with price $1.99</p></span></span></span><span style="font-family:Times New Roman;"><p align="left">A public </span></p><b><span style="font-family:Times New Roman;">makePurchase() </b></span><p align="left"><span style="font-family:Times New Roman;">method that takes the shopping cart and then prints a receipt (using your method</p><p align="left">above), packs the bags (using your method above) and displays the result (using your method above).</p><p align="left">A public </span></p><b><span style="font-family:Times New Roman;">unpackPerishables(ArrayList<grocerybag> bags) </b></span><p align="left"><span style="font-family:Times New Roman;">method that takes an ArrayList of packed</p></span><b><span style="font-family:Times New Roman;"><p align="left">GroceryBag </b></span></p><span style="font-family:Times New Roman;">objects (from your </span><b><span style="font-family:Times New Roman;">packBags() </b></span><p align="left"><span style="font-family:Times New Roman;">method) and removes all the perishable items from the bags.</p><p align="left">Note that the </span></p><b><span style="font-family:Times New Roman;">GroceryBags </b></span><p align="left"><span style="font-family:Times New Roman;">should be modified (changed) by this method in that they will have less in them</p><p align="left">afterwards. Do not discard any bags. At the end of the method, call </span></p><b><span style="font-family:Times New Roman;">displayPackedBags() </b></span><p align="left"><span style="font-family:Times New Roman;">again to see if it</p><p align="left">worked. Here is what you should see:</p></span><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><p align="left">GROCERY BAG</p><p align="left">SnackPack Pudding weighing 0.396 kg with price $0.99</p><p align="left">Nabob Coffee weighing 0.326 kg with price $3.99</p><p align="left">Gold Seal Salmon weighing 0.213 kg with price $1.99</p><p align="left">UNPACKED ITEM</p><p align="left">Coca-Cola 12-pack weighing 5.112 kg with price $3.49</p><p align="left">GROCERY BAG</p><p align="left">Ocean Spray Cranberry Cocktail weighing 2.26 kg with price $2.99</p><p align="left">Heinz Beans Original weighing 0.477 kg with price $0.79</p><p align="left">GROCERY BAG</p><p align="left">Ocean Spray Cranberry Cocktail weighing 2.26 kg with price $2.99</p><p align="left">SnackPack Pudding weighing 0.396 kg with price $0.99</p><p align="left">SnackPack Pudding weighing 0.396 kg with price $0.99</p><p align="left">GROCERY BAG</p><p align="left">GROCERY BAG</p><p align="left">UNPACKED ITEM</p><p align="left">Coca-Cola 12-pack weighing 5.112 kg with price $3.49</p><p align="left">UNPACKED ITEM</p><p align="left">Toilet Paper - 48 pack weighing 10.89 kg with price $40.96</p><p align="left">GROCERY BAG</p><p align="left">Gold Seal Salmon weighing 0.213 kg with price $1.99</p><p align="left">GROCERY BAG</p><p align="left">Ocean Spray Cranberry Cocktail weighing 2.26 kg with price $2.99</p><p align="left">Heinz Beans Original weighing 0.477 kg with price $0.79</p><p align="left">GROCERY BAG</p><p align="left">Gold Seal Salmon weighing 0.213 kg with price $1.99</p></span></span></span><span style="font-family:Times New Roman;"><p align="left">As promised, here is the testing code:</p></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">public class </b></span></span></p><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">CustomerTestProgram {</p></span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">public static void </b></span></span></p><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">main(String args[]) {</p><p align="left">GroceryItem g1 = </span></span></p><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">new </b></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">GroceryItem(</span></span><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;">"Smart-Ones Frozen Entrees"</span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">, 1.99f, 0.311f, </span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">true</b></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">);</p><p align="left">GroceryItem g2 = </span></span></p><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">new </b></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">GroceryItem(</span></span><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;">"SnackPack Pudding"</span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">, 0.99f, 0.396f, </span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">false</b></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">);</p><p align="left">GroceryItem g3 = </span></span></p><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">new </b></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">GroceryItem(</span></span><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;">"Breyers Chocolate Icecream"</span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">, 2.99f, 2.27f, </span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">true</b></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">);</p><p align="left">GroceryItem g4 = </span></span></p><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">new </b></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">GroceryItem(</span></span><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;">"Nabob Coffee"</span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">, 3.99f, 0.326f, </span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">false</b></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">);</p><p align="left">GroceryItem g5 = </span></span></p><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">new </b></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">GroceryItem(</span></span><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;">"Gold Seal Salmon"</span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">, 1.99f, 0.213f, </span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">false</b></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">);</p><p align="left">GroceryItem g6 = </span></span></p><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">new </b></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">GroceryItem(</span></span><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;">"Ocean Spray Cranberry Cocktail"</span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">, 2.99f, 2.26f, </span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">false</b></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">);</p><p align="left">GroceryItem g7 = </span></span></p><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">new </b></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">GroceryItem(</span></span><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;">"Heinz Beans Original"</span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">, 0.79f, 0.477f, </span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">false</b></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">);</p><p align="left">GroceryItem g8 = </span></span></p><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">new </b></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">GroceryItem(</span></span><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;">"Lean Ground Beef"</span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">, 4.94f, 0.75f, </span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">true</b></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">);</p><p align="left">GroceryItem g9 = </span></span></p><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">new </b></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">GroceryItem(</span></span><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;">"5-Alive Frozen Juice"</span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">, 0.75f, 0.426f, </span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">true</b></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">);</p><p align="left">GroceryItem g10 = </span></span></p><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">new </b></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">GroceryItem(</span></span><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;">"Coca-Cola 12-pack"</span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">, 3.49f, 5.112f, </span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">false</b></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">);</p><p align="left">GroceryItem g11 = </span></span></p><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">new </b></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">GroceryItem(</span></span><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;">"Toilet Paper - 48 pack"</span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">, 40.96f, 10.89f, </span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">false</b></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">);</p></span></span><span style="font-family:Courier New;font-size:85%;color:#006500;"><span style="font-family:Courier New;font-size:85%;color:#006500;"><span style="font-family:Courier New;font-size:85%;color:#006500;"><p align="left">// Make a new customer and add some items to his/her shopping cart</p></span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">Customer c = </span></span></p><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">new </b></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">Customer();</p><p align="left">c.addItem(g1);</p><p align="left">c.addItem(g2);</p><p align="left">c.addItem(g3);</p><p align="left">c.addItem(g4);</p><p align="left">c.addItem(g5);</p></span></span><span style="font-family:Courier New;font-size:85%;color:#006500;"><span style="font-family:Courier New;font-size:85%;color:#006500;"><span style="font-family:Courier New;font-size:85%;color:#006500;"><p align="left">// Check the heaviest item and whether some particular items are in there</p></span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">System.out.println(c.</span></span></p><b><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;">heaviestItem()</b></span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">); </span></span><p align="left"><span style="font-family:Courier New;font-size:85%;color:#006500;"><span style="font-family:Courier New;font-size:85%;color:#006500;"><span style="font-family:Courier New;font-size:85%;color:#006500;">//Breyers Chocolate Icecream</p></span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">System.out.println(c.</span></span></p><b><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;">alreadyHave(g1)</b></span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">); </span></span><p align="left"><span style="font-family:Courier New;font-size:85%;color:#006500;"><span style="font-family:Courier New;font-size:85%;color:#006500;"><span style="font-family:Courier New;font-size:85%;color:#006500;">//true</p></span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">System.out.println(c.</span></span></p><b><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;">alreadyHave(g2)</b></span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">); </span></span><p align="left"><span style="font-family:Courier New;font-size:85%;color:#006500;"><span style="font-family:Courier New;font-size:85%;color:#006500;"><span style="font-family:Courier New;font-size:85%;color:#006500;">//true</p></span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">System.out.println(c.</span></span></p><b><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;">alreadyHave(g8)</b></span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">); </span></span><p align="left"><span style="font-family:Courier New;font-size:85%;color:#006500;"><span style="font-family:Courier New;font-size:85%;color:#006500;"><span style="font-family:Courier New;font-size:85%;color:#006500;">//false</p></span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">System.out.println(c.</span></span></p><b><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;">alreadyHave(g9)</b></span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">); </span></span><p align="left"><span style="font-family:Courier New;font-size:85%;color:#006500;"><span style="font-family:Courier New;font-size:85%;color:#006500;"><span style="font-family:Courier New;font-size:85%;color:#006500;">//false</p><p align="left">// Now add some more items</p></span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">c.addItem(g6);</p><p align="left">c.addItem(g7);</p><p align="left">c.addItem(g8);</p><p align="left">c.addItem(g9);</p><p align="left">c.addItem(g10);</p></span></span><span style="font-family:Courier New;font-size:85%;color:#006500;"><span style="font-family:Courier New;font-size:85%;color:#006500;"><span style="font-family:Courier New;font-size:85%;color:#006500;"><p align="left">// Re-check the heaviest item and others</p></span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">System.out.println(c.</span></span></p><b><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;">heaviestItem()</b></span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">); </span></span><p align="left"><span style="font-family:Courier New;font-size:85%;color:#006500;"><span style="font-family:Courier New;font-size:85%;color:#006500;"><span style="font-family:Courier New;font-size:85%;color:#006500;">//Coca-Cola 12-pack</p></span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">System.out.println(c.</span></span></p><b><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;">alreadyHave(g8)</b></span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">); </span></span><p align="left"><span style="font-family:Courier New;font-size:85%;color:#006500;"><span style="font-family:Courier New;font-size:85%;color:#006500;"><span style="font-family:Courier New;font-size:85%;color:#006500;">//true</p></span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">System.out.println(c.</span></span></p><b><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;">alreadyHave(g9)</b></span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">); </span></span><p align="left"><span style="font-family:Courier New;font-size:85%;color:#006500;"><span style="font-family:Courier New;font-size:85%;color:#006500;"><span style="font-family:Courier New;font-size:85%;color:#006500;">//true</p><p align="left">// Now add a lot more items, somewhat randomly</p></span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">c.addItem(g1); c.addItem(g6); c.addItem(g2); c.addItem(g2);</p><p align="left">c.addItem(g3); c.addItem(g3); c.addItem(g3); c.addItem(g3);</p><p align="left">c.addItem(g3); c.addItem(g10); c.addItem(g11); c.addItem(g9);</p><p align="left">c.addItem(g5); c.addItem(g6); c.addItem(g7); c.addItem(g8);</p><p align="left">c.addItem(g8); c.addItem(g8); c.addItem(g5);</p></span></span><span style="font-family:Courier New;font-size:85%;color:#006500;"><span style="font-family:Courier New;font-size:85%;color:#006500;"><span style="font-family:Courier New;font-size:85%;color:#006500;"><p align="left">// Now make the purchase showing the receipt and packed bags</p></span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">System.out.println(</span></span></p><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;">"\n\nMaking the purchase, showing receipt and packed bags:"</span></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">);</p><p align="left">c.</span></span></p><b><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;">makePurchase()</b></span></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">;</p></span></span><span style="font-family:Courier New;font-size:85%;color:#006500;"><span style="font-family:Courier New;font-size:85%;color:#006500;"><span style="font-family:Courier New;font-size:85%;color:#006500;"><p align="left">// Finally unpack the perishables and show the packed bags again</p></span></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">System.out.println(</span></span></p><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;"><span style="font-family:Courier New;font-size:85%;color:#9b3300;">"\n\nUnpacking perishables, showing packed bags:"</span></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">);</p><p align="left">c.</span></span></p><b><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;"><span style="font-family:Courier New;font-size:85%;color:#00009b;">unpackPerishables()</b></span></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">;</p><p align="left">}</p><p align="left">}</p></span></span><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><p align="left">(4) The </span></span></span></p><b><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;">PerishableItem </b></span></span></span><p align="left"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;">subclass:</p></span></span></span><span style="font-family:Times New Roman;"><p align="left">Copy all of your code so far into a folder called </span></p><b><span style="font-family:Times New Roman;">Solutions1to3</b></span><span style="font-family:Times New Roman;">. Make sure not to simply </span><b><span style="font-family:Times New Roman;">move </b></span><p align="left"><span style="font-family:Times New Roman;">the code but to</p><p align="left">actually make a </span></p><b><span style="font-family:Times New Roman;">copy </b></span><p align="left"><span style="font-family:Times New Roman;">of it. The copy that you put in this folder will be handed in as is, do not make changes to it.</p><p align="left">This code will be a backup of your previous work to this point. We will now modify the code that you were</p><p align="left">working on.</p><p align="left">Open the </span></p><b><span style="font-family:Times New Roman;">GroceryItem.java </b></span><p align="left"><span style="font-family:Times New Roman;">file in JCreator and go through it, removing any code and variables that have to do with</p><p align="left">the item being perishable. Check all methods. Save and compile the code.</p><p align="left">Create, save and compile the following class definition in a file called </span></p><b><span style="font-family:Times New Roman;">PerishableItem.java</b></span><p align="left"><span style="font-family:Times New Roman;">:</p></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">public class </b></span></span></p><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">PerishableItem </span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">extends </b></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">GroceryItem {</p></span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">public </b></span></span></p><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">PerishableItem(String n, </span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">float </b></span></span><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">p, </span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">float </b></span></span><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">w) {</p></span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">super</b></span></span></p><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">(n, p, w);</p><p align="left">}</p><p align="left">}</p></span></span><span style="font-family:Times New Roman;"><p align="left">Open the </span></p><b><span style="font-family:Times New Roman;">GroceryBagTestProgram.java </b></span><p align="left"><span style="font-family:Times New Roman;">file in JCreator and go through the code. For all GroceryItems that were</p><p align="left">perishable, change the class name to </span></p><b><span style="font-family:Times New Roman;">PerishableItem</b></span><span style="font-family:Times New Roman;">. Lastly, remove the last parameter to the all the </span><p align="left"><b><span style="font-family:Times New Roman;">GroceryItem</p></b></span><span style="font-family:Times New Roman;"><p align="left">and </span></p><b><span style="font-family:Times New Roman;">PerishableItem </b></span><span style="font-family:Times New Roman;">constructor calls, because we discarded the </span><b><span style="font-family:Times New Roman;">perishable </b></span><p align="left"><span style="font-family:Times New Roman;">instance variable. Run this test program</p><p align="left">and make sure that it works as before. You have now made a subclass of GroceryItem and are using it. Notice that</p><p align="left">we did not really add much code at all, we just removed some useless code. However, we will now see that we need</p><p align="left">to make changes in the </span></p><b><span style="font-family:Times New Roman;">Customer </b></span><p align="left"><span style="font-family:Times New Roman;">class.</p><p align="left">Try re-compiling your </span></p><b><span style="font-family:Times New Roman;">Customer </b></span><span style="font-family:Times New Roman;">class. You should notice that your </span><b><span style="font-family:Times New Roman;">unpackPerishables() </b></span><p align="left"><span style="font-family:Times New Roman;">method no longer</p><p align="left">compiles. Modify the code so that it works again. To test it, you will have to modify the </span></p><p align="left"><b><span style="font-family:Times New Roman;">CustomerTestProgram</p></b></span><span style="font-family:Times New Roman;"><p align="left">by changing the perishable </span></p><b><span style="font-family:Times New Roman;">GroceryItem </b></span><span style="font-family:Times New Roman;">objects to </span><b><span style="font-family:Times New Roman;">PerishableItem </b></span><p align="left"><span style="font-family:Times New Roman;">objects and remove the last constructor</p><p align="left">parameter as you did before in the </span></p><b><span style="font-family:Times New Roman;">GroceryBagTestProgram</b></span><p align="left"><span style="font-family:Times New Roman;">. The test code should give the same solution as</p><p align="left">before. Do you know why we went through all this trouble ? The code is actually simpler overall.</p></span><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><p align="left">(5) The </span></span></span></p><b><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;">Carryable </b></span></span></span><p align="left"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;"><span style="font-family:Times New Roman;font-size:180%;color:#9b0000;">interface:</p></span></span></span><span style="font-family:Times New Roman;"><p align="left">Create, save and compile the following interface definition in a file called </span></p><b><span style="font-family:Times New Roman;">Carryable.java</b></span><p align="left"><span style="font-family:Times New Roman;">:</p></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">import </b></span></span></p><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">java.util.ArrayList;</p></span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">public interface </b></span></span></p><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">Carryable {</p></span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">public </b></span></span></p><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">ArrayList<groceryitem> getContents();</p></span></span><b><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;"><p align="left">public </b></span></span></p><p align="left"><span style="font-family:Courier New;font-size:85%;"><span style="font-family:Courier New;font-size:85%;">String getDescription();</p><p align="left">}</p></span></span><span style="font-family:Times New Roman;"><p align="left">Change the </span></p><b><span style="font-family:Times New Roman;">GroceryItem </b></span><span style="font-family:Times New Roman;">and </span><b><span style="font-family:Times New Roman;">GroceryBag </b></span><span style="font-family:Times New Roman;">classes so that they implement the </span><b><span style="font-family:Times New Roman;">Carryable </b></span><p align="left"><span style="font-family:Times New Roman;">interface. Note that you</p><p align="left">will have to change the first line of the class definition as well as implement the </span></p><b><span style="font-family:Times New Roman;">getContents() </b></span><span style="font-family:Times New Roman;">and </span><p align="left"><b><span style="font-family:Times New Roman;">get</p><p align="left">Description() </b></span></p><span style="font-family:Times New Roman;">methods in both these classes. For </span><b><span style="font-family:Times New Roman;">GroceryItem </b></span><span style="font-family:Times New Roman;">objects, the </span><b><span style="font-family:Times New Roman;">getContents() </b></span><p align="left"><span style="font-family:Times New Roman;">method should return an</p></span><b><span style="font-family:Times New Roman;"><p align="left">ArrayList<groceryitem> </b></span></p><span style="font-family:Times New Roman;">with that single item in it. For </span><b><span style="font-family:Times New Roman;">GroceryBag </b></span><span style="font-family:Times New Roman;">objects, the </span><b><span style="font-family:Times New Roman;">getContents() </b></span><p align="left"><span style="font-family:Times New Roman;">method should</p><p align="left">return the bag's </span></p><b><span style="font-family:Times New Roman;">items</b></span><span style="font-family:Times New Roman;">. For </span><b><span style="font-family:Times New Roman;">GroceryItem </b></span><span style="font-family:Times New Roman;">objects, the </span><b><span style="font-family:Times New Roman;">getDescription() </b></span><p align="left"><span style="font-family:Times New Roman;">method should return the following string:</p><p align="left">"</span></p><b><span style="font-family:Times New Roman;">UNPACKED ITEM</b></span><span style="font-family:Times New Roman;">" whereas for </span><b><span style="font-family:Times New Roman;">GroceryBag </b></span><span style="font-family:Times New Roman;">objects it should return "</span><b><span style="font-family:Times New Roman;">GROCERY BAG</b></span><p align="left"><span style="font-family:Times New Roman;">".</p><p align="left">Go back to your </span></p><b><span style="font-family:Times New Roman;">Customer </b></span><span style="font-family:Times New Roman;">class and modify your </span><b><span style="font-family:Times New Roman;">packBags() </b></span><span style="font-family:Times New Roman;">and </span><b><span style="font-family:Times New Roman;">displayPackedItems() </b></span><p align="left"><span style="font-family:Times New Roman;">methods so that the type</p></span><b><span style="font-family:Times New Roman;"><p align="left">ArrayList </b></span></p><span style="font-family:Times New Roman;">of backed bags is now </span><b><span style="font-family:Times New Roman;">ArrayList<carryable></b></span><span style="font-family:Times New Roman;">. Also, in your </span><b><span style="font-family:Times New Roman;">displayPackedItems() </b></span><p align="left"><span style="font-family:Times New Roman;">method, remove all</p><p align="left">code that checks instanceof. Make use of the </span></p><b><span style="font-family:Times New Roman;">getDescription() </b></span><span style="font-family:Times New Roman;">and </span><b><span style="font-family:Times New Roman;">getContents() </b></span><p align="left"><span style="font-family:Times New Roman;">methods in the interface to</p><p align="left">simplify your code. Run the </span></p><b><span style="font-family:Times New Roman;">CustomerTestProgram </b></span><p align="left"><span style="font-family:Times New Roman;">to make sure that it still works the same way with the same</p><p align="left">results.</p><p align="left">Go through your </span></p><b><span style="font-family:Times New Roman;">unpackPerishables() </b></span><p align="left"><span style="font-family:Times New Roman;">method as well and simplify it making use of the fact that the items are all</p></span><b><span style="font-family:Times New Roman;"><p align="left">Carryable</b></span></p><span style="font-family:Times New Roman;">. Remove any usage of </span><b><span style="font-family:Times New Roman;">instanceof</b></span><span style="font-family:Times New Roman;">, simplify your </span><b><span style="font-family:Times New Roman;">for </b></span><p align="left"><span style="font-family:Times New Roman;">loop and allow unpacked items to be removed as</p><p align="left">well if necessary (although in our test case, none of our unpacked items are perishable). Run the</p></span><b><span style="font-family:Times New Roman;"><p align="left">CustomerTestProgram </b></span></p><p align="left"><span style="font-family:Times New Roman;">to make sure that it still works the same way with the same results.</p><p align="left">Hopefully, you noticed how much simpler your methods became and that you understand how code can be</p><p align="left">simplified using interfaces.</p></span><b><span style="font-family:Times New Roman;"><p align="left">NOTE: For each coding question, submit your </span><span style="font-family:Times New Roman;font-size:180%;"><span style="font-family:Times New Roman;font-size:180%;">.java </span></span><span style="font-family:Times New Roman;">and your compiled </span><span style="font-family:Times New Roman;font-size:180%;"><span style="font-family:Times New Roman;font-size:180%;">.class </span></span><span style="font-family:Times New Roman;">files. </span><span style="font-family:Times New Roman;">Describe your tests</p><p>clearly in a readMe file. Submit early!!!!</p></b></span>Binh Tranhttp://www.blogger.com/profile/06892129796699737316noreply@blogger.com0