{"id":365,"date":"2012-07-17T21:34:11","date_gmt":"2012-07-18T04:34:11","guid":{"rendered":"http:\/\/blogs.unsw.edu.au\/comp1400\/?p=365"},"modified":"2012-07-17T21:57:26","modified_gmt":"2012-07-18T04:57:26","slug":"lab-wk-2-getting-to-know-bluej","status":"publish","type":"post","link":"https:\/\/blogs.unsw.edu.au\/comp1400\/blog\/2012\/07\/lab-wk-2-getting-to-know-bluej\/","title":{"rendered":"Lab Wk 2- Getting to know BlueJ"},"content":{"rendered":"<p>There are three tasks for this week&#8217;s lab:<\/p>\n<ol>\n<li>Activate your CSE account.<\/li>\n<li>Write your first program!<\/li>\n<li>Play with BlueJ<\/li>\n<\/ol>\n<p><!--more--><\/p>\n<h2>Activate your CSE account<\/h2>\n<p>The first thing we will do in this week&#8217;s lab is activate your CSE account, if you haven&#8217;t done so already. <\/p>\n<ol>\n<li>Login as &#8216;newuser&#8217;<\/li>\n<li>Follow the prompts to activate your account.<\/li>\n<li>Write your new username and password somewhere so you don&#8217;t lose it.<\/li>\n<li>Log out.<\/li>\n<li>Log back in with your new CSE login and password. Make sure you select &#8216;Windows&#8217; as your desktop.<\/li>\n<\/ol>\n<h2>Write your first program.<\/h2>\n<p>This is an exercise in breaking down a task into a sequence of simple instructions. Work in pairs. Your tutor will give each of you a small, incomplete pack of cards.<\/p>\n<ol>\n<li>Shuffle the deck.<\/li>\n<li>Go through the deck to find the smallest card.<\/li>\n<li>On a sheet of paper, write a set of instructions so that someone else can repeat the same procedure. Assume that they are very stupid and need to have ever last detail spelled out.<\/li>\n<li>Test your instructions on different size decks:\n<ul>\n<li>What if there is only 2 cards in the deck? Or only one? Or none?<\/li>\n<li>What if all the cards in the deck were the same?<\/li>\n<\/ul>\n<\/li>\n<li>Swap programs with another pair and check their code. Was it the same as yours?<\/li>\n<li>Consider: What are the <strong>objects<\/strong> in your program? What are the <strong>classes<\/strong>? What <strong>fields<\/strong> do they have? What <strong>methods<\/strong> do they provide?<\/li>\n<li>Now try writing instructions to sort the entire deck into order.<\/li>\n<\/ol>\n<h2>Experiment with BlueJ<\/h2>\n<p>Experiment with the BlueJ projects we saw in lectures.<\/p>\n<ol>\n<li>Login with your CSE login and password set up earlier<\/li>\n<li>Download the <a href=\"http:\/\/www.cse.unsw.edu.au\/~cs1400\/labs\/Turtle.zip\">Turtle.zip<\/a> <\/li>\n<li>Unzip this file to create the BlueJ project.<\/li>\n<li>Start BlueJ<\/li>\n<li>Select &#8216;Open Project&#8217; from the File menu and open the &#8216;Turtle&#8217; project.<\/li>\n<li>Create a new &#8216;MyTurtle&#8217; object by right clicking on the MyTurtle class and selecting <strong>new MyTurtle()<\/strong><\/li>\n<li>Give your turtle a name and press OK.<\/li>\n<\/ol>\n<h3>Simple shapes<\/h3>\n<ol>\n<li>Right click on the red MyTurtle object and select the <strong>void drawSquare(int sideLength)<\/strong> method.<\/li>\n<li>Enter a side length of 100 and press OK.<\/li>\n<li>Observe what happens in the World window.<\/li>\n<li>Try drawing squares of different sizes.<\/li>\n<li>What direction does the turtle face before and after you call the method?<\/li>\n<li>Double-click on the MyTurtle class to open the source-code.<\/li>\n<li>Read the <strong>drawSquare<\/strong> method. Can you explain why the turtle has a different direction after the method is called?<\/li>\n<li>What could you do to fix this so the turtle is facing the same way before and after the method?<\/li>\n<li>Change the code so that it draws a triangle instead of a square.<\/li>\n<\/ol>\n<h3>Using the debugger<\/h3>\n<ol>\n<li>Read the method <strong>drawPolygon<\/strong> and try to understand how it works.<\/li>\n<li>Run it with different parameters to see if it does what you expect.<\/li>\n<li>In the source window, click on the line number for the line &#8220;<strong>if (numberOfSides &lt; 3) {<\/strong>&#8220;. A little red stop sign should appear.<\/li>\n<li>Run the method again with numberOfSides set to 6 and sideLength set to 100. The Debugger window should appear.<\/li>\n<li>Press the <strong>Step<\/strong> button and watch how the program steps through the code.<\/li>\n<li>Run the method again with numberOfSides set to 2. Can you predict what will happen?<\/li>\n<\/ol>\n<h3>Spirals<\/h3>\n<ol>\n<li>Read the method <strong>drawSpiral<\/strong> and try to understand how it works.<\/li>\n<li>Try drawing a spiral with length = 10 on a piece of paper following these instructions.<\/li>\n<li>Use the debugger to step through the method. Does it do what you expected?<\/li>\n<li>Change the line &#8216;<strong>length = length &#8211; 2<\/strong>&#8216;  to &#8216;<strong>length = length &#8211; 4<\/strong>&#8216;. How will this change the spiral? Run it and see.<\/li>\n<li>Change the line to &#8216;<strong>length = length + 4<\/strong>&#8216;. What happens now? Why?<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>There are three tasks for this week&#8217;s lab: Activate your CSE account. Write your first program! Play with BlueJ<\/p>\n","protected":false},"author":80,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[630],"tags":[],"class_list":["post-365","post","type-post","status-publish","format-standard","hentry","category-lab"],"_links":{"self":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/365","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/users\/80"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/comments?post=365"}],"version-history":[{"count":4,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/365\/revisions"}],"predecessor-version":[{"id":369,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/365\/revisions\/369"}],"wp:attachment":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/media?parent=365"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/categories?post=365"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/tags?post=365"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}