{"id":294,"date":"2012-07-28T17:38:37","date_gmt":"2012-07-29T00:38:37","guid":{"rendered":"http:\/\/blogs.unsw.edu.au\/infs1609\/?p=294"},"modified":"2012-07-28T17:46:46","modified_gmt":"2012-07-29T00:46:46","slug":"lab-week-3-data-types","status":"publish","type":"post","link":"https:\/\/blogs.unsw.edu.au\/infs1609\/blog\/2012\/07\/lab-week-3-data-types\/","title":{"rendered":"Lab Week 3 &#8211; Data Types"},"content":{"rendered":"<p>The exercises below use the\u00a0<a title=\"Week 3 Lab\" href=\"http:\/\/www.cse.unsw.edu.au\/~is1609\/12s2\/examples\/Tut3.zip\">Tut3.zip<\/a> project for BlueJ.<\/p>\n<h3>Data types<\/h3>\n<p>What\u00a0<strong>data type<\/strong> would you use to represent the following values? Why?<\/p>\n<ol>\n<li>The length of a piece of string.<\/li>\n<li>The number of students at UNSW.<\/li>\n<li>A person\u2019s age.<\/li>\n<li>The mass of the sun.<\/li>\n<li>The exact number of stars in the Milky Way.<\/li>\n<li>The mathematical constant \u03c0.<\/li>\n<\/ol>\n<h3>Expressions<\/h3>\n<p>What are the\u00a0<strong>value<\/strong> and\u00a0<strong>type<\/strong> of the following expressions? Test your answers by typing them into the Code Pad in BlueJ. Can you explain the result?<\/p>\n<ol>\n<li>5 \/ 2<\/li>\n<li>5 % 2<\/li>\n<li>5.0 \/ 2<\/li>\n<li>5 \/ 2.0<\/li>\n<li>5.0 \/ 2.5<\/li>\n<li>5.0f \/ 2<\/li>\n<li>1.5 % 1<\/li>\n<li>1 \/ 0<\/li>\n<li>1.0 \/ 0<\/li>\n<li>10000000000 + 1<\/li>\n<li>10000000000L + 1<\/li>\n<li>10000000000.0 + 1<\/li>\n<li>10000000000.0f + 1<\/li>\n<\/ol>\n<h3>Circle area<\/h3>\n<p>The\u00a0<strong>circleArea<\/strong> method in the Tut3 class calculates the area of a circle with a given radius.<\/p>\n<ul>\n<li>Create a new Tut3 object and try calling this method with different input values.<\/li>\n<li>Add breakpoint on the first line and step through the code. Watch the \u2018local variable\u2019 panel to see variables being created and change value.<\/li>\n<li>Change the method to calculate the area of an ellipse of given width and height<\/li>\n<\/ul>\n<h3>Hand shaking<\/h3>\n<p>If there are five people Alan, Bel, Cameron, Dan, and Emily in the room and they each have to shake hands with everyone else, how many handshakes occur? What if there were 10 people? What if there were only two? Work out a general formula.<\/p>\n<p>Complete the \u2018handshakes\u2019 method in the Tut3 project to use your formula to compute the number of handshakes for a given size group.<\/p>\n<h3>The Math Class<\/h3>\n<p>For more complicated mathematical expressions, Java has a lot of built in methods in the Math class. Take a look at the\u00a0<a href=\"http:\/\/docs.oracle.com\/javase\/6\/docs\/api\/java\/lang\/Math.html\">documentation<\/a> to see what is available. Try typing the following<br \/>\nin CodePad. Explain the results.<\/p>\n<ul>\n<li>Math.sqrt(2.0)<\/li>\n<li>Math.round(3.1)<\/li>\n<li>Math.round(3.7)<\/li>\n<li>Math.min(1, 2)<\/li>\n<li>Math.max(1, 2)<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The exercises below use the\u00a0Tut3.zip project for BlueJ. Data types What\u00a0data type would you use to represent the following values? Why? The length of a piece of string. The number of students at UNSW. A person\u2019s age. The mass of the sun. The exact number of stars in the Milky Way. The mathematical constant \u03c0. [&hellip;]<\/p>\n","protected":false},"author":328,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[236],"tags":[],"class_list":["post-294","post","type-post","status-publish","format-standard","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/posts\/294","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/users\/328"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/comments?post=294"}],"version-history":[{"count":5,"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/posts\/294\/revisions"}],"predecessor-version":[{"id":299,"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/posts\/294\/revisions\/299"}],"wp:attachment":[{"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/media?parent=294"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/categories?post=294"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/infs1609\/wp-json\/wp\/v2\/tags?post=294"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}