{"id":5283,"date":"2023-11-01T17:20:19","date_gmt":"2023-11-01T17:20:19","guid":{"rendered":"https:\/\/danielschlegel.org\/wp\/?page_id=5283"},"modified":"2023-11-03T16:53:55","modified_gmt":"2023-11-03T16:53:55","slug":"programming-challenge-6-monsters","status":"publish","type":"page","link":"https:\/\/danielschlegel.org\/wp\/teaching\/csc212-fall-2023\/programming-challenge-6-monsters\/","title":{"rendered":"Programming Challenge 6:  Monsters!"},"content":{"rendered":"\n<p>In this assignment you will model two classes &#8211; monsters and monster hordes, allowing you to practice your class modeling, good programming techniques, and your use of constructs like ArrayLists.<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"327\" data-id=\"5284\" src=\"https:\/\/danielschlegel.org\/wp\/wp-content\/uploads\/2023\/11\/Screenshot-2023-10-25-at-3.40.48-PM-1024x327.png\" alt=\"\" class=\"wp-image-5284\" srcset=\"https:\/\/danielschlegel.org\/wp\/wp-content\/uploads\/2023\/11\/Screenshot-2023-10-25-at-3.40.48-PM-1024x327.png 1024w, https:\/\/danielschlegel.org\/wp\/wp-content\/uploads\/2023\/11\/Screenshot-2023-10-25-at-3.40.48-PM-300x96.png 300w, https:\/\/danielschlegel.org\/wp\/wp-content\/uploads\/2023\/11\/Screenshot-2023-10-25-at-3.40.48-PM-768x245.png 768w, https:\/\/danielschlegel.org\/wp\/wp-content\/uploads\/2023\/11\/Screenshot-2023-10-25-at-3.40.48-PM-1536x491.png 1536w, https:\/\/danielschlegel.org\/wp\/wp-content\/uploads\/2023\/11\/Screenshot-2023-10-25-at-3.40.48-PM.png 1960w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"336\" data-id=\"5285\" src=\"https:\/\/danielschlegel.org\/wp\/wp-content\/uploads\/2023\/11\/Screenshot-2023-10-25-at-3.46.48-PM-1024x336.png\" alt=\"\" class=\"wp-image-5285\" srcset=\"https:\/\/danielschlegel.org\/wp\/wp-content\/uploads\/2023\/11\/Screenshot-2023-10-25-at-3.46.48-PM-1024x336.png 1024w, https:\/\/danielschlegel.org\/wp\/wp-content\/uploads\/2023\/11\/Screenshot-2023-10-25-at-3.46.48-PM-300x98.png 300w, https:\/\/danielschlegel.org\/wp\/wp-content\/uploads\/2023\/11\/Screenshot-2023-10-25-at-3.46.48-PM-768x252.png 768w, https:\/\/danielschlegel.org\/wp\/wp-content\/uploads\/2023\/11\/Screenshot-2023-10-25-at-3.46.48-PM-1536x503.png 1536w, https:\/\/danielschlegel.org\/wp\/wp-content\/uploads\/2023\/11\/Screenshot-2023-10-25-at-3.46.48-PM.png 2014w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"206\" data-id=\"5295\" src=\"https:\/\/danielschlegel.org\/wp\/wp-content\/uploads\/2023\/11\/monsters3-1024x206.png\" alt=\"\" class=\"wp-image-5295\" srcset=\"https:\/\/danielschlegel.org\/wp\/wp-content\/uploads\/2023\/11\/monsters3-1024x206.png 1024w, https:\/\/danielschlegel.org\/wp\/wp-content\/uploads\/2023\/11\/monsters3-300x60.png 300w, https:\/\/danielschlegel.org\/wp\/wp-content\/uploads\/2023\/11\/monsters3-768x154.png 768w, https:\/\/danielschlegel.org\/wp\/wp-content\/uploads\/2023\/11\/monsters3-1536x308.png 1536w, https:\/\/danielschlegel.org\/wp\/wp-content\/uploads\/2023\/11\/monsters3.png 1942w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Why do it? <\/h2>\n\n\n\n<p>This assignment glues together nearly everything we&#8217;ve done this semester, and will provide excellent practice for the final exam!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Monster Class<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Create a new Java class called <tt>Monster<\/tt> in the <tt>horde<\/tt> package. <\/li>\n\n\n\n<li>Create the instance variables and constructor for <tt>Monster<\/tt> based on the fact that monsters have a name, a size, and a number legs, eyes, or some other physical property (if you aren&#8217;t sure if it&#8217;s OK, ask us!). You can add additional constraints (an even number of arms?) Think about what data types make sense to use for those. <em>Remember that the purpose of a constructor is to initialize the instance variables.<\/em><\/li>\n\n\n\n<li>Add a <tt>toString<\/tt> method to your <tt>Monster<\/tt> class which returns a string with the monster&#8217;s name, size, and number of whatever you chose (labeled nicely).<\/li>\n\n\n\n<li>Remember that classes are developed, not written, so create a Java main class file to test your <tt>Monster<\/tt> class. We&#8217;ll be adding some painting mechanisms to the <tt>Monster<\/tt> class in a minute, so you might want to use the skeleton at the bottom of this page. <\/li>\n\n\n\n<li>We now wish to paint our monsters. Add another instance variable to your <tt>Monster<\/tt> class for the color used, and initialize it with a random color at the appropriate point in your code.<\/li>\n\n\n\n<li>Add a method called <tt>paint<\/tt> to your <tt>Monster<\/tt> class which takes as an argument an <tt>SPainter<\/tt>. In this method, paint your monster. Make use of (at least) the defined size and number of whatever you chose. You may use circles and rectangles for drawing your monsters. Use your imagination &#8211; yours doesn&#8217;t have to look like ours! <strong>Be sure to use good practices as far as problem decomposition and invariance.<\/strong><\/li>\n\n\n\n<li>Test your <tt>Monster<\/tt> class by enhancing your tests from before. You&#8217;ll need to make an <tt>SPainter<\/tt> to pass to the <tt>Monster<\/tt>&#8216;s <tt>paint<\/tt> method. Iterate on your design until you are happy with it.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">The MonsterHorde Class<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Create a class called <tt>MonsterHorde<\/tt> in your <tt>horde<\/tt> package. <\/li>\n\n\n\n<li>Your class should have a single instance variable &#8211; an <tt>ArrayList<\/tt> of monsters. <\/li>\n\n\n\n<li>Your constructor will take one argument, the number of monsters in the horde. The goal of your constructor will be to initialize the <tt>ArrayList<\/tt> instance variable as a new empty list, and to populate it with monsters according to user input. <\/li>\n\n\n\n<li>Use the techniques we&#8217;ve used before this semester to create popup windows to ask the user for the information required to make the monsters, then add them to the <tt>ArrayList<\/tt>. Be sure you make as many as specified by the argument to the constructor!<\/li>\n\n\n\n<li>Add a <tt>toString<\/tt> method which returns a string containing the details of each monster in the horde. You should make use of the <tt>Monster<\/tt>&#8216;s <tt>toString<\/tt> method. <\/li>\n\n\n\n<li>As before, create a tester class to make sure your class is working as it should. <\/li>\n\n\n\n<li>Add a method, called <tt>paint<\/tt>, to the <tt>MonsterHorde<\/tt> class. It will take one argument, an <tt>SPainter<\/tt>. This method should make calls to the paint method in each of the monsters stored in the <tt>ArrayList<\/tt>. Paint each monster side-by-side. <\/li>\n\n\n\n<li>Test your <tt>Horde<\/tt> class by enhancing your tests from before. You&#8217;ll need to make an <tt>SPainter<\/tt> to pass to the <tt>MonsterHorde<\/tt>&#8216;s <tt>paint<\/tt> method. If it doesn&#8217;t work as you expect, go back and fix it!<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">The Testing Skeleton<\/h2>\n\n\n\n<pre class=\"java\">package horde;\n\nimport painter.SPainter;\nimport javax.swing.SwingUtilities;\n\npublic class MonsterTester {\n\n    public MonsterTester(){\n        \/\/ Create some Monster instances to test with!\n    }\n\n    public static void main(String[] args) {\n        SwingUtilities.invokeLater(new Runnable() {\n            public void run() {\n                new MonsterTester();\n            }\n        });\n    }\n}\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">The Exit<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>The assignment is due December 5th.<\/li>\n\n\n\n<li>The last day to demo will be December 8th, the last day of classes. It must be demoed on or before December 8th to receive any credit.<\/li>\n\n\n\n<li>You must post your work to you work site and demo to a TA to receive credit.<\/li>\n\n\n\n<li>Reflect on this assignment, your solution, and their relationships with the course content. Think on your engagement with the assignment and the course. <\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p class=\"lead\">In this assignment you will model two classes &#8211; monsters and monster hordes, allowing you to practice your class modeling, good programming techniques, and your use of constructs like ArrayLists. Why do it? This assignment glues together nearly everything we&#8217;ve done this semester, and will provide excellent practice for the final exam! The Monster Class The MonsterHorde Class The Testing&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"btn btn-warning\" href=\"https:\/\/danielschlegel.org\/wp\/teaching\/csc212-fall-2023\/programming-challenge-6-monsters\/\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":5285,"parent":5064,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_editorskit_title_hidden":false,"_editorskit_reading_time":3,"_editorskit_is_block_options_detached":false,"_editorskit_block_options_position":"{}","footnotes":""},"class_list":["post-5283","page","type-page","status-publish","has-post-thumbnail","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Programming Challenge 6: Monsters! - Daniel R. Schlegel<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/danielschlegel.org\/wp\/teaching\/csc212-fall-2023\/programming-challenge-6-monsters\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Programming Challenge 6: Monsters! - Daniel R. Schlegel\" \/>\n<meta property=\"og:description\" content=\"In this assignment you will model two classes &#8211; monsters and monster hordes, allowing you to practice your class modeling, good programming techniques, and your use of constructs like ArrayLists. Why do it? This assignment glues together nearly everything we&#8217;ve done this semester, and will provide excellent practice for the final exam! The Monster Class The MonsterHorde Class The Testing&hellip;Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/danielschlegel.org\/wp\/teaching\/csc212-fall-2023\/programming-challenge-6-monsters\/\" \/>\n<meta property=\"og:site_name\" content=\"Daniel R. Schlegel\" \/>\n<meta property=\"article:modified_time\" content=\"2023-11-03T16:53:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/danielschlegel.org\/wp\/wp-content\/uploads\/2023\/11\/Screenshot-2023-10-25-at-3.46.48-PM.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2014\" \/>\n\t<meta property=\"og:image:height\" content=\"660\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/danielschlegel.org\\\/wp\\\/teaching\\\/csc212-fall-2023\\\/programming-challenge-6-monsters\\\/\",\"url\":\"https:\\\/\\\/danielschlegel.org\\\/wp\\\/teaching\\\/csc212-fall-2023\\\/programming-challenge-6-monsters\\\/\",\"name\":\"Programming Challenge 6: Monsters! - Daniel R. Schlegel\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/danielschlegel.org\\\/wp\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/danielschlegel.org\\\/wp\\\/teaching\\\/csc212-fall-2023\\\/programming-challenge-6-monsters\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/danielschlegel.org\\\/wp\\\/teaching\\\/csc212-fall-2023\\\/programming-challenge-6-monsters\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/danielschlegel.org\\\/wp\\\/wp-content\\\/uploads\\\/2023\\\/11\\\/Screenshot-2023-10-25-at-3.46.48-PM.png\",\"datePublished\":\"2023-11-01T17:20:19+00:00\",\"dateModified\":\"2023-11-03T16:53:55+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/danielschlegel.org\\\/wp\\\/teaching\\\/csc212-fall-2023\\\/programming-challenge-6-monsters\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/danielschlegel.org\\\/wp\\\/teaching\\\/csc212-fall-2023\\\/programming-challenge-6-monsters\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/danielschlegel.org\\\/wp\\\/teaching\\\/csc212-fall-2023\\\/programming-challenge-6-monsters\\\/#primaryimage\",\"url\":\"https:\\\/\\\/danielschlegel.org\\\/wp\\\/wp-content\\\/uploads\\\/2023\\\/11\\\/Screenshot-2023-10-25-at-3.46.48-PM.png\",\"contentUrl\":\"https:\\\/\\\/danielschlegel.org\\\/wp\\\/wp-content\\\/uploads\\\/2023\\\/11\\\/Screenshot-2023-10-25-at-3.46.48-PM.png\",\"width\":2014,\"height\":660},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/danielschlegel.org\\\/wp\\\/teaching\\\/csc212-fall-2023\\\/programming-challenge-6-monsters\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/danielschlegel.org\\\/wp\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Teaching\",\"item\":\"https:\\\/\\\/danielschlegel.org\\\/wp\\\/teaching\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"CSC212 &#8211; Fall 2023\",\"item\":\"https:\\\/\\\/danielschlegel.org\\\/wp\\\/teaching\\\/csc212-fall-2023\\\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Programming Challenge 6: Monsters!\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/danielschlegel.org\\\/wp\\\/#website\",\"url\":\"https:\\\/\\\/danielschlegel.org\\\/wp\\\/\",\"name\":\"Daniel R. Schlegel\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/danielschlegel.org\\\/wp\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Programming Challenge 6: Monsters! - Daniel R. Schlegel","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/danielschlegel.org\/wp\/teaching\/csc212-fall-2023\/programming-challenge-6-monsters\/","og_locale":"en_US","og_type":"article","og_title":"Programming Challenge 6: Monsters! - Daniel R. Schlegel","og_description":"In this assignment you will model two classes &#8211; monsters and monster hordes, allowing you to practice your class modeling, good programming techniques, and your use of constructs like ArrayLists. Why do it? This assignment glues together nearly everything we&#8217;ve done this semester, and will provide excellent practice for the final exam! The Monster Class The MonsterHorde Class The Testing&hellip;Read more","og_url":"https:\/\/danielschlegel.org\/wp\/teaching\/csc212-fall-2023\/programming-challenge-6-monsters\/","og_site_name":"Daniel R. Schlegel","article_modified_time":"2023-11-03T16:53:55+00:00","og_image":[{"width":2014,"height":660,"url":"https:\/\/danielschlegel.org\/wp\/wp-content\/uploads\/2023\/11\/Screenshot-2023-10-25-at-3.46.48-PM.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/danielschlegel.org\/wp\/teaching\/csc212-fall-2023\/programming-challenge-6-monsters\/","url":"https:\/\/danielschlegel.org\/wp\/teaching\/csc212-fall-2023\/programming-challenge-6-monsters\/","name":"Programming Challenge 6: Monsters! - Daniel R. Schlegel","isPartOf":{"@id":"https:\/\/danielschlegel.org\/wp\/#website"},"primaryImageOfPage":{"@id":"https:\/\/danielschlegel.org\/wp\/teaching\/csc212-fall-2023\/programming-challenge-6-monsters\/#primaryimage"},"image":{"@id":"https:\/\/danielschlegel.org\/wp\/teaching\/csc212-fall-2023\/programming-challenge-6-monsters\/#primaryimage"},"thumbnailUrl":"https:\/\/danielschlegel.org\/wp\/wp-content\/uploads\/2023\/11\/Screenshot-2023-10-25-at-3.46.48-PM.png","datePublished":"2023-11-01T17:20:19+00:00","dateModified":"2023-11-03T16:53:55+00:00","breadcrumb":{"@id":"https:\/\/danielschlegel.org\/wp\/teaching\/csc212-fall-2023\/programming-challenge-6-monsters\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/danielschlegel.org\/wp\/teaching\/csc212-fall-2023\/programming-challenge-6-monsters\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/danielschlegel.org\/wp\/teaching\/csc212-fall-2023\/programming-challenge-6-monsters\/#primaryimage","url":"https:\/\/danielschlegel.org\/wp\/wp-content\/uploads\/2023\/11\/Screenshot-2023-10-25-at-3.46.48-PM.png","contentUrl":"https:\/\/danielschlegel.org\/wp\/wp-content\/uploads\/2023\/11\/Screenshot-2023-10-25-at-3.46.48-PM.png","width":2014,"height":660},{"@type":"BreadcrumbList","@id":"https:\/\/danielschlegel.org\/wp\/teaching\/csc212-fall-2023\/programming-challenge-6-monsters\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/danielschlegel.org\/wp\/"},{"@type":"ListItem","position":2,"name":"Teaching","item":"https:\/\/danielschlegel.org\/wp\/teaching\/"},{"@type":"ListItem","position":3,"name":"CSC212 &#8211; Fall 2023","item":"https:\/\/danielschlegel.org\/wp\/teaching\/csc212-fall-2023\/"},{"@type":"ListItem","position":4,"name":"Programming Challenge 6: Monsters!"}]},{"@type":"WebSite","@id":"https:\/\/danielschlegel.org\/wp\/#website","url":"https:\/\/danielschlegel.org\/wp\/","name":"Daniel R. Schlegel","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/danielschlegel.org\/wp\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/P83Tb6-1nd","_links":{"self":[{"href":"https:\/\/danielschlegel.org\/wp\/wp-json\/wp\/v2\/pages\/5283","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/danielschlegel.org\/wp\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/danielschlegel.org\/wp\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/danielschlegel.org\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/danielschlegel.org\/wp\/wp-json\/wp\/v2\/comments?post=5283"}],"version-history":[{"count":6,"href":"https:\/\/danielschlegel.org\/wp\/wp-json\/wp\/v2\/pages\/5283\/revisions"}],"predecessor-version":[{"id":5296,"href":"https:\/\/danielschlegel.org\/wp\/wp-json\/wp\/v2\/pages\/5283\/revisions\/5296"}],"up":[{"embeddable":true,"href":"https:\/\/danielschlegel.org\/wp\/wp-json\/wp\/v2\/pages\/5064"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/danielschlegel.org\/wp\/wp-json\/wp\/v2\/media\/5285"}],"wp:attachment":[{"href":"https:\/\/danielschlegel.org\/wp\/wp-json\/wp\/v2\/media?parent=5283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}