{"id":921,"date":"2013-11-21T15:39:59","date_gmt":"2013-11-21T08:39:59","guid":{"rendered":"http:\/\/kusumotolab.com\/?p=921"},"modified":"2013-11-21T15:39:59","modified_gmt":"2013-11-21T08:39:59","slug":"aoop-lab-day-3","status":"publish","type":"post","link":"https:\/\/oldblog.kusumotolab.com\/?p=921","title":{"rendered":"AOOP Lab Day 3 (ArrayList,LinkedList,Iterator)"},"content":{"rendered":"<h1>Package flower.lib<\/h1>\n<h2>Flower.java<\/h2>\n<pre lang=\"java\">\r\npackage flower.lib;\r\n\r\npublic class Flower {\r\n\t\r\n\tpublic Flower(int p) {\r\n\t\tthis.price = p;\r\n\t}\r\n\t\r\n\tpublic Flower() {\r\n\t\tthis.price = 0;\r\n\t}\r\n\t\r\n\t\r\n\tprotected int price;\r\n\t\r\n\tpublic void printDetail() {\r\n\t\tSystem.out.println(\"Flower\");\r\n\t}\r\n\t\r\n\tpublic int getPrice() {\r\n\t\treturn price;\r\n\t}\r\n}\r\n\r\n<\/pre>\n<h2>Orchid.java<\/h2>\n<pre lang=\"Java\">\r\npackage flower.lib;\r\n\r\npublic class Orchid extends Flower{\r\n\t\r\n\tpublic Orchid(int p) {\r\n\t\tthis.price = p;\r\n\t}\r\n\t\r\n\tpublic Orchid() {\r\n\t\tthis.price = 6;\r\n\t}\r\n\t\r\n\tpublic void printDetail() {\r\n\t\tSystem.out.println(\"Orchid\");\r\n\t}\r\n\t\r\n\tpublic int getPrice() {\r\n\t\treturn price;\r\n\t}\r\n}\r\n\r\n<\/pre>\n<h2>Sunflower.java<\/h2>\n<pre lang=\"Java\">\r\npackage flower.lib;\r\n\r\npublic class Sunflower extends Flower{\r\n\tpublic Sunflower(int p) {\r\n\t\tthis.price = p;\r\n\t}\r\n\t\r\n\tpublic Sunflower() {\r\n\t\tthis.price = 1;\r\n\t}\r\n\t\r\n\tpublic void printDetail() {\r\n\t\tSystem.out.println(\"Sunflower\");\r\n\t}\r\n\t\r\n\tpublic int getPrice() {\r\n\t\treturn price;\r\n\t}\r\n}\r\n<\/pre>\n<h2>Tulip.java<\/h2>\n<pre lang=\"Java\">\r\npackage flower.lib;\r\n\r\npublic class Tulip extends Flower{\r\n\tpublic Tulip(int p) {\r\n\t\tthis.price = p;\r\n\t}\r\n\t\r\n\tpublic Tulip() {\r\n\t\tthis.price = 5;\r\n\t}\r\n\t\r\n\tpublic void printDetail() {\r\n\t\tSystem.out.println(\"Tulip\");\r\n\t}\r\n\t\r\n\tpublic int getPrice() {\r\n\t\treturn price;\r\n\t}\r\n}\r\n\r\n<\/pre>\n<h1>Package flower.program<\/h1>\n<h2>Flower_store.java<\/h2>\n<pre lang=\"Java\">\r\npackage flower.program;\r\nimport java.io.IOException;\r\nimport java.util.ArrayList;\r\nimport java.util.LinkedList;\r\nimport java.util.Scanner;\r\nimport java.util.Iterator;\r\n\r\n\r\n\r\n\r\nimport flower.lib.*;\r\n\r\npublic class Flower_store {\r\n\r\n\tpublic static void main(String[] args) throws IOException {\r\n\t\tScanner s = new Scanner(System.in);\r\n\t\tint rm;\r\n\t\t\/\/int count = 0;\r\n\t\t\/\/Flower[] bouquest = new Flower[1000];\r\n\t\t\/\/ArrayList<Flower> b = new ArrayList<Flower>();\r\n\t\tLinkedList<Flower> c = new LinkedList<Flower>();\r\n\t\tSystem.out.println(\"Welcome to flower program!!\");\r\n\t\twhile(true) {\r\n\t\tSystem.out.println(\"What type of flower would you like to add in to your bouquet?\");\r\n\t\tSystem.out.println(\"[s]unflower, [t]ulip, [o]rchid, [q]uit, [v]iew, [r]eset, re[m]ove current bouquet\");\r\n\t\tString input = s.next();\r\n\t\t\/\/System.out.println(input);\r\n\t\t\r\n\t\tif (input.equalsIgnoreCase(\"s\")) {\r\n\t\t\t\/\/bouquest[count] = new Sunflower();\r\n\t\t\t\/\/b.add(new Sunflower());\r\n\t\t\tc.add(new Sunflower());\r\n\t\t\t\/\/count++;\r\n\t\t\t\r\n\t\t\t\/\/Sunflower f1 = new Sunflower(1);\r\n\t\t\t\/\/count = (count + f1.getPrice());\r\n\t\t}else if (input.equalsIgnoreCase(\"t\")){\r\n\t\t\t\/\/bouquest[count] = new Tulip();\r\n\t\t\tc.add(new Tulip());\r\n\t\t\t\/\/b.add(new Tulip());\r\n\t\t\t\/\/count++;\r\n\t\t\t\r\n\t\t\t\/\/Tulip f2 = new Tulip(5);\r\n\t\t\t\/\/count = (count + f2.getPrice());\r\n\t\t\t\r\n\t\t}else if (input.equalsIgnoreCase(\"o\")){\r\n\t\t\t\/\/bouquest[count] = new Orchid();\r\n\t\t\tc.add(new Orchid());\r\n\t\t\t\/\/b.add(new Orchid());\r\n\t\t\t\/\/count++;\r\n\t\t\t\r\n\t\t\t\/\/Orchid f3 = new Orchid(6);\r\n\t\t\t\/\/count = (count + f3.getPrice());\r\n\t\t\t\r\n\t\t}else if (input.equalsIgnoreCase(\"v\")) {\r\n\t\t\tSystem.out.println(\"----- Your Bouquet -----\");\r\n\t\t\tint cost=0;\r\n\t\t\t\/*for (int i=0; i<c.size(); i++) {\r\n\t\t\t\/\/for (int i=0; i<b.size(); i++) {\r\n\t\t\t\tSystem.out.print((i+1)+\". \");\r\n\t\t\t\t\/\/bouquest[i].printDetail();\r\n\t\t\t\tc.get(i).printDetail();\r\n\t\t\t\t\/\/b.get(i).printDetail();\r\n\t\t\t\tcost += c.get(i).getPrice();\r\n\t\t\t\t\/\/cost += b.get(i).getPrice();\r\n\t\t\t\t\/\/cost = cost + bouquest[i].getPrice();\r\n\t\t\t}\r\n\t\t\t*\/\r\n\t\t\t\/*int i = 0;\r\n\t\t\twhile(i<c.size()) {\r\n\t\t\t\tc.get(i).printDetail();\r\n\t\t\t\tcost += c.get(i).getPrice();\r\n\t\t\t\ti++;\r\n\t\t\t}\r\n\t\t\t*\/\r\n\t\t\t\r\n\t\t\tIterator <Flower> itr = c.iterator();\r\n\t\t\twhile(itr.hasNext()) {\r\n\t\t\t\tFlower e = itr.next();\r\n\t\t\t\te.printDetail();\r\n\t\t\t\tcost += e.getPrice();\t\t\t\r\n\t\t\t}\r\n\t\t\t\/\/System.out.println(b.size());\r\n\t\t\tSystem.out.println(\"------------------------\");\r\n\t\t\tSystem.out.println(\"Total cost is $\"+cost);\r\n\t\t\t\/\/System.out.println(\"Total cost is $\"+total);\r\n\t\t\tSystem.out.println(\"------------------------\");\r\n\t\t}else if (input.equalsIgnoreCase(\"r\")) {\r\n\t\t\t\/*for (int i=0; i<count; i++) {\r\n\t\t\t\t\/\/bouquest[i] = null;\r\n\t\t\t}*\/\r\n\t\t\tc.clear();\r\n\t\t\t\/\/b.clear();\r\n\t\t\tSystem.out.println(\"Reset current bouquet Complete.\");\r\n\t\t\t\/\/count = 0;\r\n\t\t}else if (input.equalsIgnoreCase(\"m\")) {\r\n\t\t\tSystem.out.print(\"Enter Your item to remove? : \");\r\n\t\t\trm = s.nextInt();\r\n\t\t\ttry {\r\n\t\t\tc.remove(rm-1);\r\n\t\t\tSystem.out.println(\"Complete!\");\r\n\t\t\t}catch (Exception e){\r\n\t\t\t\tSystem.out.println(\"Error to Remove, Try again\");\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tif (input.equalsIgnoreCase(\"q\")) {\r\n\t\t\tSystem.out.println(\"Bye Bye!\");\r\n\t\t\tSystem.exit(0);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n}\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Package flower.lib Flower.java package flower.lib; public class Flower { public Flower(int p) { this.price = p; } public Flower() { this.price = 0; } protected int price; public void printDetail() { System.out.println(&#8220;Flower&#8221;); } public int getPrice() { return price; } } Orchid.java package flower.lib; public class Orchid extends Flower{ public Orchid(int p) { this.price = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":[]},"categories":[54,59],"tags":[],"class_list":["post-921","post","type-post","status-publish","format-standard","hentry","category-homework","category-java"],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3OMEb-eR","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/oldblog.kusumotolab.com\/index.php?rest_route=\/wp\/v2\/posts\/921","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oldblog.kusumotolab.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/oldblog.kusumotolab.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/oldblog.kusumotolab.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oldblog.kusumotolab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=921"}],"version-history":[{"count":1,"href":"https:\/\/oldblog.kusumotolab.com\/index.php?rest_route=\/wp\/v2\/posts\/921\/revisions"}],"predecessor-version":[{"id":922,"href":"https:\/\/oldblog.kusumotolab.com\/index.php?rest_route=\/wp\/v2\/posts\/921\/revisions\/922"}],"wp:attachment":[{"href":"https:\/\/oldblog.kusumotolab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=921"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oldblog.kusumotolab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=921"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oldblog.kusumotolab.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=921"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}