{"id":15524,"date":"2023-04-18T22:00:53","date_gmt":"2023-04-18T22:00:53","guid":{"rendered":"https:\/\/www.goodacademic.com\/blog\/questions\/im-working-on-a-java-question-and-need-the-explanation-and-answer-to-help-me-learn\/"},"modified":"2023-04-18T22:00:53","modified_gmt":"2023-04-18T22:00:53","slug":"im-working-on-a-java-question-and-need-the-explanation-and-answer-to-help-me-learn","status":"publish","type":"questions","link":"https:\/\/www.goodacademic.com\/blog\/questions\/im-working-on-a-java-question-and-need-the-explanation-and-answer-to-help-me-learn\/","title":{"rendered":"I&#8217;m working on a java question and need the explanation and answer to help me learn."},"content":{"rendered":"<div class=\"col-sm-12 messageContent\">\n <b>Learning Goal: <\/b>I&#8217;m working on a computer science question and need the explanation and answer to help me learn.<\/p>\n<p><strong>COMPLETE IN JAVA<\/strong><\/p>\n<p>O<span style=\"background-color: initial;\">verview: Cleo is a cat that likes to climb up to high places and watch birds. Every day she<\/span><\/p>\n<p>escapes her cage and wanders until she finds a good location. At the end of every day you need<\/p>\n<p>to find Cleo and return her to her cage. For this project you will write a program to determine<\/p>\n<p>the locations where Cleo may decide to perch.<\/p>\n<p>Details: You have mapped the rectangular island where Cleo lives by dividing it into a grid of<\/p>\n<p>cells with r rows and c columns (like a 2-d array). Cleo\u00e2\u20ac\u2122s cage is at location row x and column y.<\/p>\n<p>Each square has a height (above sea level). When Cleo escapes her cage she walks according to<\/p>\n<p>the following rules:<\/p>\n<li>Cleo will never move from a square to a lower square.<\/li>\n<li>Cleo may move to one of the four adjacent squares if the adjacent square is the same or<\/li>\n<p>greater height.<\/p>\n<li>Cleo may stop if none of the four adjacent squares is higher.<\/li>\n<p>The input will be provided in a file named input.txt which will be placed in the same directory<\/p>\n<p>as your java file. The format of this file will be a sequence of whitespace separated integers. The<\/p>\n<p>first line will contain r and c. The second line will contain x and y. The next r lines will contain<\/p>\n<p>the c heights of the cells in that row.<\/p>\n<p>Your output will consist of a line with n the number of locations where Cleo may stop and each<\/p>\n<p>of the next n lines will be the locations where Cleo may stop. No other output should appear in<\/p>\n<p>the final project. See the examples below.<\/p>\n<p>The easiest way to solve the problem is to read the data file into a 2-d array, treat the cells of the<\/p>\n<p>array as nodes, have a directed edge from a cell\/node to an adjacent cell\/node if the height of the<\/p>\n<p>adjacent cell is the same or larger, run BFS or DFS to determine which cells are reachable, and<\/p>\n<p>check whether Cleo might stop at the cell\/node by seeing if it is at least as high as the adjacent<\/p>\n<p>cells.<\/p>\n<p>required project specifications:<\/p>\n<p>Consist of 1 or more dot-java files (no class files, zip files, input files, or other files should<\/p>\n<p>be submitted).\u00e2\u20ac\u00a2 have each file begin with your name and project number.<\/p>\n<li>not be placed into any package.<\/li>\n<li>have one file called Project1.java.<\/li>\n<li>compile with the command \u00e2\u20ac\u02dcjavac Project1.java\u00e2\u20ac\u2122.<\/li>\n<li>run using the command \u00e2\u20ac\u02dcjava Project1\u00e2\u20ac\u2122.<\/li>\n<li>accept input from a file called input.txt in the same directory as the java file(s) formatted<\/li>\n<p>precisely as described above.<\/p>\n<li>accomplishes the goal of the project. In other words, the output should be the correct<\/li>\n<p>answer formatted correctly.<\/p>\n<p>Examples:<\/p>\n<p>If input.txt contains:<\/p>\n<p>5 5<\/p>\n<p>2 2<\/p>\n<p>9 9 9 9 9<\/p>\n<p>9 8 1 8 9<\/p>\n<p>9 1 5 1 9<\/p>\n<p>9 8 1 8 9<\/p>\n<p>9 9 9 9 9<\/p>\n<p>then the output would be<\/p>\n<p>1<\/p>\n<p>2 2<\/p>\n<p>since Cleo cannot leave the square where she starts without going down.<\/p>\n<p>If input.txt contains:<\/p>\n<p>5 5<\/p>\n<p>2 2<\/p>\n<p>1 9 7 8 1<\/p>\n<p>1 1 5 1 1<\/p>\n<p>1 1 3 4 5<\/p>\n<p>1 1 5 1 1<\/p>\n<p>1 8 7 7 7<\/p>\n<p>then the output would be:<\/p>\n<p>6<\/p>\n<p>0 1<\/p>\n<p>0 3<\/p>\n<p>2 4<\/p>\n<p>4 1<\/p>\n<p>4 3<\/p>\n<p>4 4<\/p>\n<p>Note all 6 of these locations are at least as high as their neighbors and any square not containing<\/p>\n<p>a 1 is reachable.<\/p>\n<p>If input.txt contains:<\/p>\n<p>8 8<\/p>\n<p>0 0<\/p>\n<p>1 2 3 4 5 6 7 7<\/p>\n<p>1 2 3 4 5 6 7 8<\/p>\n<p>2 3 4 1 1 1 1 1<\/p>\n<p>2 3 2 1 2 2 2 2<\/p>\n<p>3 4 3 1 5 2 5 5<\/p>\n<p>4 5 2 1 2 2 8 9<\/p>\n<p>5 6 3 1 6 2 8 4<\/p>\n<p>1 7 5 1 5 2 1 9<\/p>\n<p>then the output would be:<\/p>\n<p>4<\/p>\n<p>0 6<\/p>\n<p>1 7<\/p>\n<p>2 2<\/p>\n<p>7 1<\/p>\n<p>because there are 4 locations that Cleo can wander to and might stop. For example, Cleo could<\/p>\n<p>walk from (0,0) to (0,1) to (0,2) to (0,3) to (0,4) to (0,5) to (0,6) and stop, since the heights don\u00e2\u20ac\u2122t<\/p>\n<p>decrease: 1, 2, 3, &#8230;,7 and the cells adjacent to (0,6) are not higher. Similarly, Cleo could walk<\/p>\n<p>from (0,0) to (1,0) to (2,0) to (3,0) to (4,0) to (5,0) to (6,0) to (6,1) to (7,1) and stop, since the<\/p>\n<p>heights don\u00e2\u20ac\u2122t decrease 1, 1, 2, 2, 3, 4, 5, 6, 7 and the cells adjacent to (7,1) aren\u00e2\u20ac\u2122t higher.<\/p>\n<p>Note that the list does not contain (0,7) because a neighbor (1,7) is higher and does not contain<\/p>\n<p>(7,7) because it is unreachable.<\/p>\n<p>COMPLETE IN JAVA<\/p>\n<div class=\"questions-requirements\">\n<p class=\"requirement\">Requirements: complete<\/p>\n<\/p><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Learning Goal: I&#8217;m working on a computer science question and need the explanation and answer to help me learn. COMPLETE IN JAVA Overview: Cleo is a cat that likes to climb up to high places and watch birds. Every day she escapes her cage and wanders until she finds a good location. At the end [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":[],"disciplines":[211],"paper_types":[],"tagged":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/questions\/15524"}],"collection":[{"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/questions"}],"about":[{"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/types\/questions"}],"author":[{"embeddable":true,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/comments?post=15524"}],"version-history":[{"count":0,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/questions\/15524\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/media?parent=15524"}],"wp:term":[{"taxonomy":"disciplines","embeddable":true,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/disciplines?post=15524"},{"taxonomy":"paper_types","embeddable":true,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/paper_types?post=15524"},{"taxonomy":"tagged","embeddable":true,"href":"https:\/\/www.goodacademic.com\/blog\/wp-json\/wp\/v2\/tagged?post=15524"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}