{"id":163,"date":"2021-01-01T22:42:01","date_gmt":"2021-01-01T22:42:01","guid":{"rendered":"https:\/\/bhiggs.x10hosting.com\/practical-java-programming\/?page_id=163"},"modified":"2021-01-02T21:20:41","modified_gmt":"2021-01-02T21:20:41","slug":"assignment-5","status":"publish","type":"page","link":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/assignments\/assignment-5\/","title":{"rendered":"Assignment 5"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a6d4709b1d87\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a6d4709b1d87\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/assignments\/assignment-5\/#Inheritance_and_Polymorphism\" >Inheritance and Polymorphism<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/assignments\/assignment-5\/#Part_1_Drawing_Shapes_Preparing_the_Infrastructure\" >Part 1: Drawing Shapes: Preparing the Infrastructure<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/assignments\/assignment-5\/#Heres_What_To_Do\" >Here&#8217;s What To Do:<\/a><ul class='ez-toc-list-level-5' ><li class='ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/assignments\/assignment-5\/#Write_a_set_of_classes_that_satisfies_the_Shapes_Specification\" >Write a set of classes that satisfies the&nbsp;Shapes Specification.&nbsp;<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/assignments\/assignment-5\/#Use_These_Classes_to_Produce_Equivalent_Results_to_the_Previous_Assignment\" >Use These Classes to Produce Equivalent Results to the Previous Assignment<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/assignments\/assignment-5\/#Finally_To_Ensure_That_You_Did_Things_Correctly\" >Finally, To Ensure That You Did Things Correctly:<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/assignments\/assignment-5\/#Part_2_Drawing_Shapes_Generalizing_the_Problem\" >Part 2: Drawing Shapes: Generalizing the Problem<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/assignments\/assignment-5\/#Heres_What_To_Do-2\" >Here&#8217;s What To Do:<\/a><ul class='ez-toc-list-level-5' ><li class='ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/assignments\/assignment-5\/#Hints\" >Hints:<\/a><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Inheritance_and_Polymorphism\"><\/span>Inheritance and Polymorphism<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The previous assignment solved a single specific problem: drawing points with automatic scaling. What if we wanted to draw something else besides a set of points? Rather than starting from scratch all over again, it would be nice to be able to build on what we&#8217;ve already done, to provide even more useful functionality.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We&#8217;ll use an Object-Oriented approach called <em><strong>Inheritance<\/strong><\/em> and <em><strong>Polymorphism<\/strong><\/em>, and use these techniques to construct a set of classes which make it easy to draw any shape we&#8217;d like, and in the process reuse a lot of our code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The assignment is divided into two parts:<\/p>\n\n\n\n<ol class=\"wp-block-list\" type=\"A\"><li><a href=\"#part-1\">The basic infrastructure: <em>Drawing Points <\/em><\/a><\/li><li><a href=\"#part-2\">Expanding on what we&#8217;ve done: <em>Drawing Shapes <\/em><\/a><\/li><\/ol>\n\n\n\n<div style=\"height:31px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong><em><u>Note:<\/u><\/em><\/strong> I want to see <em>separate submissions for each of the parts<\/em>. That is, I want you to consider them separate from the point of view of describing what you did, providing listings and output, etc. So expect to submit two separate Word documents, one for each part.<\/p><\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"part-1\"><span class=\"ez-toc-section\" id=\"Part_1_Drawing_Shapes_Preparing_the_Infrastructure\"><\/span>Part 1: Drawing Shapes: Preparing the Infrastructure<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">What might we need to accomplish this?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First, we&#8217;ll need a convenient place to draw our shapes. What can we draw shapes on? A Swing <code><strong>JPanel<\/strong><\/code> seems appropriate. So what if we derive our class from class <code><strong>JPanel<\/strong><\/code> &#8212; how about a <strong><code>ShapesPanel<\/code><\/strong>?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Second, we should have some way of translating between the coordinate system of our <strong><code>ShapesPanel<\/code><\/strong> and the coordinate system required to display the data &#8212; a kind of adapter class. Remember our <strong><code>CoordinateSystem<\/code><\/strong> class? That&#8217;s its job.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, we&#8217;ll need some shapes to draw. Unfortunately, if we use the standard Java classes <strong><code>Point<\/code><\/strong>, <strong><code>Rectangle<\/code><\/strong>, etc., they&#8217;re not really shapes, and they don&#8217;t know how to draw themselves.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><em><strong><u>Note:<\/u><\/strong><\/em> I find it curious that the same folks who gave us this incredible Object-Oriented programming language didn&#8217;t, in its original version, provide even a basic set of object-oriented shape classes <br>In the JSDK version 1.2 and beyond, they provide a set of classes for doing two dimensional drawing &#8212; the 2D API &#8212; but that&#8217;s a topic for another course.<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">Since shapes have a set of common attributes and behavior, let&#8217;s first create a class that captures that common stuff &#8212; class <strong><code>Shape<\/code><\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Then we&#8217;ll at least have to create a class that represents a point &#8212; class&nbsp;<strong><code>Point<\/code><\/strong>, derived from class <strong><code>Shape<\/code><\/strong>. Note that our class <strong><code>Point<\/code><\/strong> is <strong><em>not<\/em><\/strong> the same as <strong><code>java.awt.Point<\/code><\/strong>. Under some circumstances, you may need to explicitly qualify one or the other of these classes to ensure they don&#8217;t conflict with each other.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em><strong><u>Note:<\/u><\/strong><\/em> Do <em><strong>not<\/strong><\/em> change the name of your Point class!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em><strong><u>Hint:<\/u><\/strong><\/em> Do <strong><em>not<\/em><\/strong> use wildcard importation, such as the following:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>import java.awt.*;<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>or:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>import javax.swing.*;<\/strong><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Heres_What_To_Do\"><\/span><strong>Here&#8217;s What To Do:<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Write_a_set_of_classes_that_satisfies_the_Shapes_Specification\"><\/span><strong>Write a set of classes that satisfies the&nbsp;<a href=\"http:\/\/bhiggs.x10hosting.com\/Javadocs\/shape-docs\/\" target=\"_blank\" rel=\"noreferrer noopener\">Shapes Specification<\/a>.&nbsp;<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">Note that this specification is for the entire assignment, but in this part, we&#8217;ll just focus on the following classes:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code><strong>screen.ScreenCoordinate<\/strong><\/code><\/li><li><code><strong>shapes.Shape<\/strong><\/code><\/li><li><code><strong>shapes.Point<\/strong><\/code><\/li><li><code><strong>shapes.ShapesPanel<\/strong><\/code><\/li><li><code><strong>shapes.ShapesTest<\/strong><\/code><\/li><li><code><strong>world.Bounds<\/strong><\/code><\/li><li><code><strong>world.Coordinate<\/strong><\/code><\/li><li><code><strong>world.CoordinateSystem<\/strong><\/code><u> <\/u><\/li><\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong><em><u>Note:&nbsp;<\/u><\/em><\/strong>This assignment uses a&nbsp;<code>CoordinateSystem<\/code>&nbsp;class that has been changed and enhanced from the version in the previous assignment.<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">In this part, you should&nbsp;<em>ignore the following classes<\/em>:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code><strong>shapes.FilledRectangle<\/strong><\/code><\/li><li><code><strong>shapes.Line<\/strong><\/code><\/li><li><code><strong>shapes.Rectangle<\/strong><\/code><\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s the order in which you probably should implement the classes you need for this part of the assignment:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><code><strong>Coordinate and ScreenCoordinate<\/strong><\/code><\/li><li><code><strong>Bounds<\/strong><\/code><\/li><li><code><strong>CoordinateSystem<\/strong><\/code><\/li><li><code><strong>Shape<\/strong><\/code><\/li><li><code><strong>Point<\/strong><\/code><\/li><li><code><strong>ShapesPanel<\/strong><\/code><\/li><li><code><strong>ShapesTest<\/strong><\/code><\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">(You can implement them in any order you like, but since the classes have interdependencies, you&#8217;ll probably have trouble if you deviate from the above order too much.)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I encourage you to progressively implement&nbsp;<em>small<\/em>&nbsp;pieces of each class, get something that compiles and (to some extent) runs, and then iterate a number of times over them to produce the final result. It&#8217;s always a good idea to implement a small piece, get it working, and then add to it progressively. Don&#8217;t try to add everything at once, or you&#8217;ll likely get stuck and become quite frustrated!<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><em><strong><u>Note:<\/u>&nbsp;<\/strong><\/em>I have intentionally organized these classes into three packages:&nbsp;<code><strong>shapes<\/strong><\/code>,&nbsp;<code><strong>world<\/strong><\/code>, and&nbsp;<code><strong>screen<\/strong><\/code>. It is important to keep these classes in these specified packages.&nbsp;<br><strong><em>As before, you may not change the specification, except to add&nbsp;<code>main()<\/code>&nbsp;methods for testing purposes.<\/em><\/strong><\/p><\/blockquote>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Use_These_Classes_to_Produce_Equivalent_Results_to_the_Previous_Assignment\"><\/span><strong>Use These Classes to Produce Equivalent Results to the Previous Assignment<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">My solution produced the following results for the set of points specified in assignment 4:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"300\" height=\"200\" src=\"https:\/\/bhiggs.x10hosting.com\/practical-java-programming\/wp-content\/uploads\/2021\/01\/points1.gif\" alt=\"\" class=\"wp-image-169\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Finally_To_Ensure_That_You_Did_Things_Correctly\"><\/span><strong>Finally, To Ensure That You Did Things Correctly:<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">Change the set of points to be displayed by the&nbsp;<code><strong>ShapesTest<\/strong><\/code>&nbsp;class to:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\nprivate static Shape&#x5B;] m_shapes =\n{\nnew Point(0.0, 0.0),\nnew Point(4.903926402016152, 0.9754516100806413),\nnew Point(9.238795325112868, 3.8268343236508975),\nnew Point(12.472044184538179, 8.333553495294034),\nnew Point(14.142135623730951, 14.14213562373095),\nnew Point(13.889255825490057, 20.78674030756363),\nnew Point(11.480502970952696, 27.716385975338603),\nnew Point(6.828161270564491, 34.32748481411306),\nnew Point(2.4492935982947065E-15, 40.0),\nnew Point(-8.77906449072577, 44.13533761814537),\nnew Point(-19.134171618254488, 46.19397662556434),\nnew Point(-30.556362816078106, 45.730828676639995),\nnew Point(-42.426406871192846, 42.42640687119285),\nnew Point(-54.04552479966545, 36.11206514627414),\nnew Point(-64.67156727579008, 26.787840265556262),\nnew Point(-73.5588960302423, 14.631774151209578),\nnew Point(-80.0, -6.12570991828312E-14),\nnew Point(-83.36674883427457, -16.582677371370984),\nnew Point(-83.14915792601576, -34.44150891285818),\nnew Point(-78.98961316874173, -52.77917213686232),\nnew Point(-70.71067811865464, -70.71067811865487),\nnew Point(-58.33487446705808, -87.30430929176735),\nnew Point(-42.09517756015967, -101.62674857624162),\nnew Point(-22.435387031854496, -112.79030724637155),\nnew Point(2.977005887073927E-13, -120.0),\nnew Point(24.386290252016366, -122.59816005040373),\nnew Point(49.748846207462016, -120.10433922646713),\nnew Point(75.00198145764665, -112.24839766084337),\nnew Point(98.99494936611698, -98.99494936611632),\nnew Point(120.56309378386935, -80.5576837878419),\nnew Point(138.58192987669324, -57.40251485476294),\nnew Point(152.02171846250084, -30.238999912499278),\nnew Point(160.0, 6.713540381873849E-13),\nnew Point(161.82957126653287, 32.18990313266188),\nnew Point(157.05952052691845, 65.05618350206599),\nnew Point(145.50718215294495, 97.2247907784311),\nnew Point(127.2792206135779, 127.2792206135792),\nnew Point(102.7804931086256, 153.82187827597141),\nnew Point(72.7098521493661, 175.53711117714488),\nnew Point(38.042612793143924, 191.25312967863016),\nnew Point(-1.1822174476228077E-12, 200.0),\nnew Point(-39.99351601330753, 201.06098248266198),\nnew Point(-80.36352079666992, 194.01470182736978),\nnew Point(-119.44760009921532, 178.76596664504666),\nnew Point(-155.56349186104111, 155.5634918610398),\nnew Point(-187.0806627680731, 125.00330242940987),\nnew Point(-212.4922924775962, 88.01718944397007),\nnew Point(-230.48454089475925, 45.84622567378966),\nnew Point(-240.0, -3.3815107191745065E-13),\nnew Point(-240.29239369879141, -47.7971288939516),\nnew Point(-230.96988312782167, -95.67085809127246),\nnew Point(-212.0247511371491, -141.67040941999844),\nnew Point(-183.8477631085026, -183.8477631085021),\nnew Point(-147.22611175019503, -220.33944726017418),\nnew Point(-103.3245267385749, -249.44747377804714),\nnew Point(-53.64983855443617, -269.71595211088817),\nnew Point(-1.114775216380581E-12, -280.0),\nnew Point(55.60074177459526, -279.5238049149209),\nnew Point(110.9781953858746, -267.92506442827374),\nnew Point(163.8932187407812, -245.28353562925182),\nnew Point(212.13203435596284, -212.13203435596566),\nnew Point(253.59823175227504, -169.44892107098056),\nnew Point(286.4026550784979, -118.63186403318012),\nnew Point(308.94736332701706, -61.45345143508309),\nnew Point(320.0, -2.9989257333312617E-12),\nnew Point(318.75521613105053, 63.404354655238485),\nnew Point(304.880245728726, 126.28553268047635),\nnew Point(278.54232012135475, 186.11602806156355),\nnew Point(240.4163056034291, 240.41630560342327),\nnew Point(191.67173039176643, 286.85701624437564),\nnew Point(133.93920132778575, 323.35783637894855),\nnew Point(69.25706431573045, 348.17877454314583),\nnew Point(5.314300478934592E-12, 360.0),\nnew Point(-71.2079675358813, 357.9866273471802),\nnew Point(-141.59286997507772, 341.8354270291784),\nnew Point(-208.33883738234562, 311.80110461345794),\nnew Point(-268.70057685088335, 268.7005768508928),\nnew Point(-320.11580073647605, 213.89453971255264),\nnew Point(-360.313017679399, 149.2465386223918),\nnew Point(-387.41018575927455, 77.06067719637821),\nnew Point(-400.0, 8.060899453190573E-12),\nnew Point(-397.21803856330996, -79.01158041652369),\nnew Point(-378.7906083296307, -156.90020726967936),\nnew Point(-345.05988910556096, -230.5616467031279),\nnew Point(-296.9848480983562, -296.98484809834366),\nnew Point(-236.11734903333863, -353.37458522857656),\nnew Point(-164.5538759169975, -397.2681989798496),\nnew Point(-84.86429007702566, -426.64159697540333),\nnew Point(-1.0457125646763092E-11, -440.0),\nnew Point(86.81519329716642, -436.44944977943965),\nnew Point(172.20754456427997, -415.7457896300834),\nnew Point(252.78445602390923, -378.3186735976646),\nnew Point(325.26911934580323, -325.26911934582046),\nnew Point(386.6333697206765, -258.34015835412555),\nnew Point(434.22338028029975, -179.86121321160428),\nnew Point(465.8730081915318, -92.6679029576742),\nnew Point(480.0, -1.399511880474836E-11),\nnew Point(475.6808609955696, 94.61880617780803),\nnew Point(452.7009709305362, 187.5148818588802),\nnew Point(411.57745808976847, 275.00726534469027),\nnew Point(353.553390593285, 353.5533905932625),\nnew Point(280.5629676749128, 419.8921542127762),\nnew Point(195.1685505062114, 471.1785615807498),\nnew Point(100.47151583832317, 505.1044194076603),\nnew Point(1.7964336191386278E-11, 520.0),\nnew Point(-102.42241905844921, 514.9122722116996),\nnew Point(-202.82221915347998, 489.6561522309893),\nnew Point(-297.23007466547097, 444.83624258187257),\nnew Point(-381.8376618407214, 381.8376618407499),\nnew Point(-453.15093870487567, 302.78577699570036),\nnew Point(-508.13374288119957, 210.47588780081898),\nnew Point(-544.3358306237886, 108.27512871897255),\nnew Point(-560.0, 2.2364777806676846E-11),\nnew Point(-554.1436834278297, -110.22603193908998),\nnew Point(-526.6113335314425, -218.12955644807943),\nnew Point(-478.0950270739769, -319.4528839862512),\nnew Point(-410.12193308821503, -410.12193308818007),\nnew Point(-325.0085863164884, -486.4097231969749),\nnew Point(-225.78322509542696, -545.0889241816492),\nnew Point(-116.07874159962239, -583.567241839917),\nnew Point(-2.7196443650620066E-11, -600.0),\nnew Point(118.02964481973031, -593.3750946439599),\nnew Point(233.43689374267845, -563.5665148318958),\nnew Point(341.67569330703117, -511.3538115660815),\nnew Point(438.40620433563845, -438.40620433568057),\nnew Point(519.6685076890739, -347.2313956372767),\nnew Point(582.0441054820988, -241.09056239003527),\nnew Point(622.7986530560452, -123.88235448027261),\nnew Point(640.0, -3.245933372321593E-11),\nnew Point(632.6065058600901, 125.83325770037023),\nnew Point(600.5216961323493, 248.74423103727707),\nnew Point(544.6125960581863, 363.89850262781073),\nnew Point(466.69047558314634, 466.69047558309643),\nnew Point(369.4542049580654, 552.9272921811726),\nnew Point(256.397899684644, 618.9992867825481),\nnew Point(131.68596736092329, 662.0300642721733),\nnew Point(3.815344802446445E-11, 680.0),\nnew Point(-133.6368705810097, 671.8379170762205),\nnew Point(-264.05156833187533, 637.476877432803),\nnew Point(-386.12131194858995, 577.8713805502914),\nnew Point(-494.9747468305542, 494.9747468306124),\nnew Point(-586.186076673271, 391.6770142788545),\nnew Point(-655.9544680829973, 271.7052369792532),\nnew Point(-701.2614754883012, 139.48958024157437),\nnew Point(-720.0, 4.4278786554365614E-11),\nnew Point(-711.0693282923509, -141.4404834616488),\nnew Point(-674.4320587332569, -279.35890562647313),\nnew Point(-611.1301650423967, -408.3441212693688),\nnew Point(-523.2590180780787, -523.2590180780116),\nnew Point(-413.8998235996438, -619.4448611653693),\nnew Point(-287.01257427386275, -692.9096493834462),\nnew Point(-147.2931931222259, -740.4928867044292),\nnew Point(-5.083534931291943E-11, -760.0),\nnew Point(149.24409634228743, -750.3007395084813),\nnew Point(294.6662429210706, -711.3872400337109),\nnew Point(430.5669305901473, -644.3889495345022),\nnew Point(551.5432893254687, -551.5432893255455),\nnew Point(652.7036456574673, -436.12263292043366),\nnew Point(729.8648306838951, -302.31991156847266),\nnew Point(779.7242979205571, -155.0968060028778),\nnew Point(800.0, -5.78231363001259E-11),\nnew Point(789.5321507246119, 157.04770922292565),\nnew Point(748.3424213341651, 309.9735802156676),\nnew Point(677.6477340266081, 452.78973991092545),\nnew Point(579.8275605730124, 579.8275605729254),\nnew Point(458.34544224122374, 685.9624301495651),\nnew Point(317.627248863083, 766.8200119843438),\nnew Point(162.90041888353014, 818.9557091366848),\nnew Point(6.524214751598501E-11, 840.0),\nnew Point(-164.85132210356346, 828.7635619407426),\nnew Point(-325.28091751026426, 785.2976026346194),\nnew Point(-475.0125492317033, 710.906518518714),\nnew Point(-608.111831820382, 608.1118318204797),\nnew Point(-719.2212146416626, 480.56825156201415),\nnew Point(-803.7751932847923, 332.9345861576938),\nnew Point(-858.1871203528125, 170.70403176418293),\nnew Point(-880.0, 7.309238296049678E-11),\nnew Point(-867.9949731568734, -172.65493498420085),\nnew Point(-822.2527839350739, -340.58825480486047),\nnew Point(-744.1653030108204, -497.23535855248065),\nnew Point(-636.3961030679474, -636.3961030678381),\nnew Point(-502.7910608828051, -752.4799991337601),\nnew Point(-348.2419234523049, -840.7303745852406),\nnew Point(-178.50764464483612, -897.4185315689402),\nnew Point(-8.137384263366119E-11, -920.0),\nnew Point(180.45854786483778, -907.2263843730043),\nnew Point(355.89559209945634, -859.2079652355287),\nnew Point(519.4581678732577, -777.4240875029268),\nnew Point(664.6803743152941, -664.6803743154153),\nnew Point(785.7387836258571, -525.0138702035962),\nnew Point(877.6855558856887, -363.54926074691645),\nnew Point(936.6499427850677, -186.31125752548976),\nnew Point(960.0, -9.008652653547826E-11),\nnew Point(946.4577955891351, 188.26216074547432),\nnew Point(896.1631465359835, 371.2029293940518),\nnew Point(810.6828719950336, 541.6809771940344),\nnew Point(692.9646455628834, 692.9646455627498),\nnew Point(547.2366795243878, 818.9975681179538),\nnew Point(378.8565980415284, 914.6407371861368),\nnew Point(194.1148704061438, 975.8813540011952),\n};\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">To obtain this source code, you can copy and paste the above into your Java IDE.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After you&#8217;ve made the changes, see what your program displays!&nbsp;&nbsp;<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>You shouldn&#8217;t have to make&nbsp;<em>any other changes<\/em>&nbsp;to the classes you wrote for this part of the assignment other than changing the&nbsp;<code><strong>m_shapes<\/strong><\/code>&nbsp;array, above.&nbsp; If you do have to make additional changes to make this last part work correctly, you need to go back and ensure that the earlier parts of this assignment still work.<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">If your program doesn&#8217;t show anything reasonable, or if it doesn&#8217;t display all the points in the&nbsp;<strong><code>ShapesPanel<\/code><\/strong>, or if it doesn&#8217;t scale properly, then go back and fix the problems, and make sure that the program still works with the original set of points.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"part-2\"><span class=\"ez-toc-section\" id=\"Part_2_Drawing_Shapes_Generalizing_the_Problem\"><\/span>Part 2: Drawing Shapes: Generalizing the Problem<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In this section, you&#8217;ll write a program that displays the data in a histogram form, like this:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><img decoding=\"async\" width=\"300\" height=\"200\" src=\"https:\/\/bhiggs.x10hosting.com\/practical-java-programming\/wp-content\/uploads\/2021\/01\/histogram1.gif\" alt=\"\" class=\"wp-image-175\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:12px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">with the same resizing behavior as before:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><img decoding=\"async\" width=\"275\" height=\"286\" src=\"https:\/\/bhiggs.x10hosting.com\/practical-java-programming\/wp-content\/uploads\/2021\/01\/histogram2.gif\" alt=\"\" class=\"wp-image-176\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:13px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">In other words:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>display the original points (in black)<\/li><li>display green lines connecting the points<\/li><li>display the data in the form of a histogram by drawing red rectangles<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Because we&#8217;re displaying rectangles based at the x axis (where y = 0), we&#8217;re including a larger region of world coordinate space, so the points appear to move upward in the window, compared with the results of the last part of this assignment.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We&#8217;ll be using&nbsp;<em>inheritance<\/em>&nbsp;and&nbsp;<em>polymorphism<\/em>&nbsp;to simplify the job. We&#8217;ve done all the hard work in Part A &#8212; this should be quite a bit simpler, if you&#8217;ve done things properly in Part A.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To implement this, you will need refer to the\u00a0<a href=\"http:\/\/bhiggs.x10hosting.com\/Javadocs\/shapesA_docs\/\" target=\"_blank\" rel=\"noreferrer noopener\"><em><strong>Specification<\/strong><\/em><\/a>\u00a0again;\u00a0 we&#8217;ll be implementing more of the classes specified therein.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Heres_What_To_Do-2\"><\/span><strong>Here&#8217;s What To Do:<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<ol class=\"wp-block-list\"><li>Write the&nbsp;<code><strong>shapes.Line<\/strong><\/code>&nbsp;and&nbsp;<code><strong>shapes.Rectangle<\/strong><\/code>&nbsp;classes.<\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Bear in mind:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Both&nbsp;<code><strong>Line<\/strong><\/code>&nbsp;and&nbsp;<code><strong>Rectangle<\/strong><\/code>&nbsp;will extend class&nbsp;<code>Shape<\/code>.&nbsp;<\/li><li>Ignore the&nbsp;<code><strong>FilledRectangle<\/strong><\/code>&nbsp;class; that will be used in the next section.<\/li><li>Augment your&nbsp;<code><strong>ShapesTest<\/strong><\/code>&nbsp;class to use the above classes to produce the above results.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Once you&#8217;ve implemented these classes, and augmented the <code><strong>ShapesTe<\/strong>st<\/code> class appropriately, you should see results like the above images.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How will you draw the histogram?<\/p>\n\n\n\n<div class=\"wp-block-group has-white-background-color has-background\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<h5 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Hints\"><\/span><em><strong>Hints:<\/strong><\/em><span class=\"ez-toc-section-end\"><\/span><\/h5>\n\n\n\n<ul class=\"wp-block-list\"><li>Note that the points are all spaced evenly in the x direction, so you can figure out the width of each rectangle quite easily from the x coordinates of the points. Each point should be centered in its corresponding rectangle.&nbsp; The height of the rectangle should be determined by recognizing that the base of the rectangle is on the x axis (where y = 0), and the top of the rectangle should intersect with the corresponding point.<\/li><li>Think about the order in which you need to draw the three sets of graphical objects so that they display correctly.&nbsp; This will be reflected in how you specify the shapes in your&nbsp;<code><strong>m_shapes<\/strong><\/code>&nbsp;array in the&nbsp;<code><strong>ShapesTest<\/strong><\/code>&nbsp;class.<\/li><li>You should not have to change any of the classes implemented in Part 1 in order to get this to work. If you think you must make a change to them, you&#8217;re probably doing something wrong!&nbsp; Try to figure out what you did wrong, and correct it,&nbsp;<strong><em>highlighting what you changed<\/em><\/strong>. I want to see what you did to make this work!<\/li><\/ul>\n<\/div><\/div>\n\n\n\n<ol class=\"wp-block-list\" start=\"2\"><li><strong>Write the&nbsp;<code><strong>shapes.FilledRectangle<\/strong><\/code>&nbsp;class<\/strong><\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Here, we will modify your program to display the histogram slightly differently:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"200\" src=\"https:\/\/bhiggs.x10hosting.com\/practical-java-programming\/wp-content\/uploads\/2021\/01\/filledHistogram1.gif\" alt=\"\" class=\"wp-image-181\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:15px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Notice that our rectangles are now filled with a different color. This is where the&nbsp;<strong><code>FilledRectangle<\/code><\/strong>&nbsp;class comes in:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Implement the&nbsp;<code><strong>FilledRectangle<\/strong><\/code>&nbsp;class, per the specification.<\/li><li>Modify your&nbsp;<code><strong>ShapesTest<\/strong><\/code>&nbsp;class to use the&nbsp;<code><strong>FilledRectangle<\/strong><\/code>&nbsp;class, in place of the&nbsp;<code><strong>Rectangle<\/strong><\/code>&nbsp;class, to produce the above results.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><em><strong><u>Notes:<\/u><\/strong><\/em><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>There should be no need to change any other classes to make this work.<\/li><li>The implementation of&nbsp;<code><strong>FilledRectangle<\/strong><\/code>&nbsp;should be relatively simple. (A lot of the work is already done in the&nbsp;<code>Rectangle<\/code>&nbsp;class.)<\/li><li>The changes to&nbsp;<code><strong>ShapesTest<\/strong><\/code>&nbsp;should be simple &#8212; just change the&nbsp;<code>Rectangle<\/code>s referred to in the&nbsp;<code>m_shapes<\/code>&nbsp;array to&nbsp;<code>FilledRectangle<\/code>s.<\/li><\/ul>\n\n\n\n<ol class=\"wp-block-list\" start=\"3\"><li><strong>See Whether You&#8217;ve Implemented Things Correctly:<\/strong><\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Change the contents of the&nbsp;<code>m_shapes<\/code>&nbsp;array to the following:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; quick-code: false; notranslate\" title=\"\">\npublic static Shape&#x5B;] m_shapes =\n{\nnew FilledRectangle(-4.999999999999994, 95.0, 5.000000000000006, 105.0, Color.cyan, Color.blue),\nnew FilledRectangle(-100.10565162951535, 25.901699437494752, -90.10565162951535, 35.901699437494756, Color.cyan, Color.green),\nnew FilledRectangle(-63.77852522924732, -85.90169943749473, -53.77852522924732, -75.90169943749473, Color.cyan, Color.red),\nnew FilledRectangle(53.77852522924729, -85.90169943749476, 63.77852522924729, -75.90169943749476, Color.cyan, Color.magenta),\nnew FilledRectangle(90.10565162951536, 25.901699437494717, 100.10565162951536, 35.90169943749471, Color.cyan, Color.orange),\nnew Line(6.123233995736766E-15, 100.0, -58.77852522924732, -80.90169943749473, Color.blue),\nnew Line(6.123233995736766E-15, 100.0, 58.77852522924729, -80.90169943749476, Color.blue),\nnew Line(-95.10565162951535, 30.901699437494752, 58.77852522924729, -80.90169943749476, Color.green),\nnew Line(-95.10565162951535, 30.901699437494752, 95.10565162951536, 30.901699437494717, Color.green),\nnew Line(-58.77852522924732, -80.90169943749473, 95.10565162951536, 30.901699437494717, Color.red),\nnew Line(-58.77852522924732, -80.90169943749473, 6.123233995736766E-15, 100.0, Color.red),\nnew Line(58.77852522924729, -80.90169943749476, 6.123233995736766E-15, 100.0, Color.magenta),\nnew Line(58.77852522924729, -80.90169943749476, -95.10565162951535, 30.901699437494752, Color.magenta),\nnew Line(95.10565162951536, 30.901699437494717, -95.10565162951535, 30.901699437494752, Color.orange),\nnew Line(95.10565162951536, 30.901699437494717, -58.77852522924732, -80.90169943749473, Color.orange),\nnew Line(-150.0, 0.0, +150.0, 0.0, Color.black),\nnew Line(0.0, -150.0, 0.0, +150.0, Color.black),\nnew Point(0.0, 0.0, Color.red),\n};\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">and see what your application displays.&nbsp;(You can copy out of the above and paste it into your Java IDE.)<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>Hint:<\/strong> To get the best view of this, resize your display so that it&#8217;s square, rather than rectangular.<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">It should display something interesting, and it should automatically display all of the above shapes in the window (no shapes, or parts thereof, should be outside of the display. The entire display should scale appropriately as you resize the window.&nbsp; If all of these don&#8217;t happen, you need to figure out what the problem is.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Inheritance and Polymorphism The previous assignment solved a single specific problem: drawing points with automatic scaling. What if we wanted to draw something else besides a set of points? Rather than starting from scratch all over again, it would be nice to be able to build on what we&#8217;ve already done, to provide even more [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":102,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_eb_attr":"","_uag_custom_page_level_css":"","ocean_front_end_style_editor":"no","ocean_post_layout":"left-sidebar","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"ocs-assignments-sidebar","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","footnotes":""},"class_list":["post-163","page","type-page","status-publish","hentry","entry"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"ocean-thumb-m":false,"ocean-thumb-ml":false,"ocean-thumb-l":false},"uagb_author_info":{"display_name":"Bryan Higgs","author_link":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/author\/bryan\/"},"uagb_comment_info":0,"uagb_excerpt":"Inheritance and Polymorphism The previous assignment solved a single specific problem: drawing points with automatic scaling. What if we wanted to draw something else besides a set of points? Rather than starting from scratch all over again, it would be nice to be able to build on what we&#8217;ve already done, to provide even more&hellip;","_links":{"self":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/pages\/163","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/comments?post=163"}],"version-history":[{"count":13,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/pages\/163\/revisions"}],"predecessor-version":[{"id":249,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/pages\/163\/revisions\/249"}],"up":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/pages\/102"}],"wp:attachment":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/media?parent=163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}