{"id":305,"date":"2011-10-10T17:22:15","date_gmt":"2011-10-11T00:22:15","guid":{"rendered":"http:\/\/blogs.unsw.edu.au\/comp1400\/?p=305"},"modified":"2011-10-14T22:33:46","modified_gmt":"2011-10-15T05:33:46","slug":"sample-prac-exam","status":"publish","type":"post","link":"https:\/\/blogs.unsw.edu.au\/comp1400\/blog\/2011\/10\/sample-prac-exam\/","title":{"rendered":"Sample Prac Exam"},"content":{"rendered":"<p>The Prac Exam for COMP1400 will take place in labs in Week 13. <\/p>\n<ul>\n<li>Please make sure you turn up to your designated lab time. You will not be allowed to sit the exam at another time.<\/li>\n<li>The exam will be open book, so you will have access to the web and any texts you care to bring. We will be monitoring you, however, to make sure you do not communicate with others during the exam.<\/li>\n<li>This exam is worth 40% of your final mark. <\/li>\n<\/ul>\n<p>The questions below are a <strong>sample<\/strong> of the kinds of questions you will receive in the test.<\/p>\n<p><!--more--><br \/>\nYou have 2 hours to complete this exam. There are three questions. Each question is worth equal marks, but they are not of equal difficulty. Start each question in a separate BlueJ project. See the end of this post for details on how to submit your solutions.<\/p>\n<h2>Question 1 &#8211; Whiffle Ball<\/h2>\n<p>Whiffle ball is a single-player game. The rules are as follows:<\/p>\n<ol>\n<li>You start with <strong>zero score<\/strong> and <strong>10 moves<\/strong>.<\/li>\n<li>When you start a new game you designate a <strong>target<\/strong> score you want to reach.<\/li>\n<li>On each turn, you can either <strong>shoot<\/strong> or <strong>leap<\/strong>.\n<li>Shooting costs <strong>one turn<\/strong> and gives you <strong>one point<\/strong>.<\/li>\n<li>Leaping <strong>multiplies your score<\/strong> by the height you leap (in feet). It costs <strong>one turn per foot<\/strong> you jump.<\/li>\n<li>You cannot shoot or leap if you don&#8217;t have <strong>enough turns<\/strong> left to pay the cost.<\/li>\n<li>To win, your score at the end of the game must be <strong>exactly equal<\/strong> to your target.<\/li>\n<\/ol>\n<p>Your task is to create a <code>WhiffleBall<\/code> class which implements these rules. It should include the following public methods:<\/p>\n<ul>\n<li>A constructor <code>WhiffleBall(int target)<\/code> which starts a new game with the given target<\/li>\n<li>Accessor methods:\n<ul>\n<li><code>getScore()<\/code> returns your current score<\/li>\n<li><code>getTarget()<\/code> returns your target score<\/li>\n<li><code>getMovesRemaining()<\/code> returns the number of moves left<\/li>\n<li><code>haveWon()<\/code> returns true if the game is over and you have achieved the target, false otherwise<\/li>\n<\/ul>\n<\/li>\n<li>Mutator methods:\n<ul>\n<li><code>shoot()<\/code> perform the shoot action.<\/li>\n<li><code>leap(int height)<\/code> perform the leap action to the height given.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>Question 2 &#8211; Cats<\/h2>\n<p>Download the BlueJ project <a href=\"http:\/\/www.cse.unsw.edu.au\/~cs1400\/prac-exam\/prac-exam-sample-q2.zip\">prac-exam-sample-q2<\/a>.<\/p>\n<p>This project is part of a database for a veternarian&#8217;s practice. It implements a <code>Cat<\/code> class which is used to represent a cat and keep track of the year in which it was last vaccinated.<\/p>\n<p>Your task is to write a <code>VaccinationTracker<\/code> class which scans a list of cats to find which ones have not been vaccinated recently. The frequency of vaccinations is given in years in the constructor of the class. <\/p>\n<p>Your class should which implements the following:<\/p>\n<ul>\n<li>A constructor <code>VaccinationTracker(int frequency)<\/code> which creates a new VaccinationTracker with the specified freqency.<\/li>\n<li>A constructor <code>VaccinationTracker()<\/code> which creates a new VaccinationTracker with the default frequency of 5 years.<\/li>\n<li>A method <code>requiresVaccination(int year, ArrayList list)<\/code> which takes as parameters the current year and a list of cats. It should return another list containing those cats whose last vaccination was at least as long ago as the frequency specified in the constructor OR who have never been vaccinated at all.<\/li>\n<\/ul>\n<p>Example usage:<br \/>\n<code><br \/>\n   Cat ginger = new Cat(\"Ginger\");<br \/>\n   ginger.setLastVaccination(2008);<br \/>\n   Cat tom = new Cat(\"Tom\");<br \/>\n   tom.setLastVaccination(2007);<br \/>\n   Cat lolCat = new Cat(\"LolCat\");  \/\/ never vaccinated<br \/>\n   Cat angus = new Cat(\"Angus\");<br \/>\n   angus.setLastVaccination(2009);<br \/>\n   ArrayList cats = new ArrayList();<br \/>\n   cats.add(ginger);<br \/>\n   cats.add(tom);<br \/>\n   cats.add(lolCat);<br \/>\n   cats.add(angus);<\/p>\n<p>   VaccinationTracker tracker = new VaccinationTracker(3);<br \/>\n   ArrayList filtered = tracker.requiresVaccination(2011, cats);<br \/>\n<\/code><br \/>\nAfter this code executes, <code>filtered<\/code> should equal <code>[ginger, tom, lolCat]<\/code> <br \/>and the list <code>cats<\/code> should be unchanged: <code>[ginger, tom, lolCat, angus]<\/code>.<\/p>\n<h2>Question 3 &#8211; Battle<\/h2>\n<p>Download the BlueJ project <a href=\"http:\/\/www.cse.unsw.edu.au\/~cs1400\/prac-exam\/prac-exam-sample-q3.zip\">prac-exam-sample-q3<\/a>.<\/p>\n<p>In it you will find the class <code>Player<\/code> which represents a player in a Player-vs-Player fighting game. It contains code to implement the player&#8217;s health, strength and the weapon they are wielding. It also provides an <code>attack()<\/code> method which allows one player to attack another. <strong>Do not modify<\/strong> this class.<\/p>\n<p>Your job is to implement a base <code>Weapon<\/code> class and with three subclasses: <code>PoisonedWeapon<\/code>, <code>Boulder<\/code> and <code>LifeDrainer<\/code>. The details of these classes is given below:<\/p>\n<h3>Weapon<\/h3>\n<p>The base <code>Weapon<\/code> class has a fixed probability of hitting (expressed as a percentage) and a fixed damage value (in health points). These values should be set in a constructor:<\/p>\n<ul>\n<li><code>public Weapon(int hitProb, int damage)<\/code><\/li>\n<\/ul>\n<p>The class should implement two public methods:<\/p>\n<ul>\n<li><code>public int hitProbability(Player attacker, Player target)<\/code> which returns the probability that the specified target can hit the victim.<\/li>\n<li><code>public void hit(Player attacker, Player target)<\/code> which implements the result of the attacker hitting the target<\/li>\n<\/ul>\n<p>In the base <code>Weapon<\/code> class, <code>hitProbability<\/code> should return the percentage given in the constructor and <code>hit<\/code> should inflict the damage given in the constructor on the target.<\/p>\n<p>The are specialised weapon subclasses should modify this default behaviour: <\/p>\n<h3>PoisonedWeapon<\/h3>\n<p>A <code>PoisonedWeapon<\/code> has the same hit probabilty and damage as a normal weapon but has the additional effect of removing one point of the target&#8217;s strength when it hits.<\/p>\n<p>It should have the constructor:<\/p>\n<ul>\n<li><code>public PoisonedWeapon(int hitProb, int damage)<\/code><\/li>\n<\/ul>\n<p>and any other methods you think are necessary.<\/p>\n<h3>Boulder<\/h3>\n<p>A <code>Boulder<\/code> has a hit probability the same as a normal weapon, but it only applies if the attacker&#8217;s strength is greater than the target&#8217;s. If it is equal or less, the hit probability is zero. <\/p>\n<p>When a boulder hits, it should kill the target immediately. <\/p>\n<p>It should have the constructor:<\/p>\n<ul>\n<li><code>public Boulder(int hitProb)<\/code> &#8211; the hitProb is the probability of hitting a <strong>weaker<\/strong> opponent.<\/li>\n<\/ul>\n<p>and any other methods you think are necessary.<\/p>\n<h3>LifeDrainer<\/h3>\n<p>A <code>LifeDrainer<\/code> has the same hit probability and damage as a normal weapon, but has the additional feature that a successful hit heals the attacker by as many health points as it removes from the target.<\/p>\n<p>It should have the constructor:<\/p>\n<ul>\n<li><code>public LifeDrainer(int hitProb, int damage)<\/code><\/li>\n<\/ul>\n<p>and any other methods you think are necessary.<\/p>\n<h2>Submitting  your code<\/h2>\n<p><strong>These are just example instructions. Do NOT submit your answers to these sample questions.<\/strong><\/p>\n<p>You will be submitting your solutions online in the same way you submitted your assignments:<\/p>\n<ol>\n<li>Select &#8220;<strong>Create Jar File&#8230;<\/strong>&#8221; In the Project menu in BlueJ.<\/li>\n<li>In the dialog box make sure the &#8220;<strong>Include source<\/strong>&#8221;  box is checked.<\/li>\n<li>Press <strong>Continue<\/strong><\/li>\n<li>Save with the filename &#8220;<strong>q1.jar<\/strong>&#8220;, &#8220;<strong>q2.jar<\/strong>&#8220;, or &#8220;<strong>q3.jar<\/strong>&#8221; for questions 1, 2 and 3 respectively.<\/li>\n<li>Go to <a href=\"https:\/\/cgi.cse.unsw.edu.au\/~give\/Student\/give.php\">https:\/\/cgi.cse.unsw.edu.au\/~give\/Student\/give.php<\/a><\/li>\n<li>Login with your <strong>CSE username<\/strong> and password<\/li>\n<li>Type <strong>COMP1400<\/strong> in the Course field and press Search<\/li>\n<li>Select <strong>prac_exam_q1<\/strong>, <strong>prac_exam_q2<\/strong>, or <strong>prac_exam_q3<\/strong> from the list of assignments and press <strong>Upload my assignment<\/strong><\/li>\n<li>Select <strong>Browse<\/strong> to locate your <strong>q[123].jar<\/strong> file.<\/li>\n<li>Press <strong>Submit my files<\/strong>.<\/li>\n<li>Check the response to make sure your submission was processed correctly.<\/li>\n<\/ol>\n<p><strong>NOTE:<\/strong> You can submit as often as you like. Only the last submission will be marked. <strong>Do NOT leave it to the last minute<\/strong>. Submit each question as you go. Marks will be awarded for partial solutions, so always try to submit something even if it doesn&#8217;t work.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Prac Exam for COMP1400 will take place in labs in Week 13. Please make sure you turn up to your designated lab time. You will not be allowed to sit the exam at another time. The exam will be open book, so you will have access to the web and any texts you care [&hellip;]<\/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-305","post","type-post","status-publish","format-standard","hentry","category-lab"],"_links":{"self":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/305","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=305"}],"version-history":[{"count":21,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/305\/revisions"}],"predecessor-version":[{"id":322,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/posts\/305\/revisions\/322"}],"wp:attachment":[{"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/media?parent=305"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/categories?post=305"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.unsw.edu.au\/comp1400\/wp-json\/wp\/v2\/tags?post=305"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}