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 to bring. We will be monitoring you, however, to make sure you do not communicate with others during the exam.
- This exam is worth 40% of your final mark.
The questions below are a sample of the kinds of questions you will receive in the test.
You 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.
Question 1 – Whiffle Ball
Whiffle ball is a single-player game. The rules are as follows:
- You start with zero score and 10 moves.
- When you start a new game you designate a target score you want to reach.
- On each turn, you can either shoot or leap.
- Shooting costs one turn and gives you one point.
- Leaping multiplies your score by the height you leap (in feet). It costs one turn per foot you jump.
- You cannot shoot or leap if you don’t have enough turns left to pay the cost.
- To win, your score at the end of the game must be exactly equal to your target.
Your task is to create a WhiffleBall
class which implements these rules. It should include the following public methods:
- A constructor
WhiffleBall(int target)
which starts a new game with the given target - Accessor methods:
getScore()
returns your current scoregetTarget()
returns your target scoregetMovesRemaining()
returns the number of moves lefthaveWon()
returns true if the game is over and you have achieved the target, false otherwise
- Mutator methods:
shoot()
perform the shoot action.leap(int height)
perform the leap action to the height given.
Question 2 – Cats
Download the BlueJ project prac-exam-sample-q2.
This project is part of a database for a veternarian’s practice. It implements a Cat
class which is used to represent a cat and keep track of the year in which it was last vaccinated.
Your task is to write a VaccinationTracker
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.
Your class should which implements the following:
- A constructor
VaccinationTracker(int frequency)
which creates a new VaccinationTracker with the specified freqency. - A constructor
VaccinationTracker()
which creates a new VaccinationTracker with the default frequency of 5 years. - A method
requiresVaccination(int year, ArrayList list)
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.
Example usage:
Cat ginger = new Cat("Ginger");
ginger.setLastVaccination(2008);
Cat tom = new Cat("Tom");
tom.setLastVaccination(2007);
Cat lolCat = new Cat("LolCat"); // never vaccinated
Cat angus = new Cat("Angus");
angus.setLastVaccination(2009);
ArrayList cats = new ArrayList();
cats.add(ginger);
cats.add(tom);
cats.add(lolCat);
cats.add(angus);
VaccinationTracker tracker = new VaccinationTracker(3);
ArrayList filtered = tracker.requiresVaccination(2011, cats);
After this code executes, filtered
should equal [ginger, tom, lolCat]
and the list cats
should be unchanged: [ginger, tom, lolCat, angus]
.
Question 3 – Battle
Download the BlueJ project prac-exam-sample-q3.
In it you will find the class Player
which represents a player in a Player-vs-Player fighting game. It contains code to implement the player’s health, strength and the weapon they are wielding. It also provides an attack()
method which allows one player to attack another. Do not modify this class.
Your job is to implement a base Weapon
class and with three subclasses: PoisonedWeapon
, Boulder
and LifeDrainer
. The details of these classes is given below:
Weapon
The base Weapon
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:
public Weapon(int hitProb, int damage)
The class should implement two public methods:
public int hitProbability(Player attacker, Player target)
which returns the probability that the specified target can hit the victim.public void hit(Player attacker, Player target)
which implements the result of the attacker hitting the target
In the base Weapon
class, hitProbability
should return the percentage given in the constructor and hit
should inflict the damage given in the constructor on the target.
The are specialised weapon subclasses should modify this default behaviour:
PoisonedWeapon
A PoisonedWeapon
has the same hit probabilty and damage as a normal weapon but has the additional effect of removing one point of the target’s strength when it hits.
It should have the constructor:
public PoisonedWeapon(int hitProb, int damage)
and any other methods you think are necessary.
Boulder
A Boulder
has a hit probability the same as a normal weapon, but it only applies if the attacker’s strength is greater than the target’s. If it is equal or less, the hit probability is zero.
When a boulder hits, it should kill the target immediately.
It should have the constructor:
public Boulder(int hitProb)
– the hitProb is the probability of hitting a weaker opponent.
and any other methods you think are necessary.
LifeDrainer
A LifeDrainer
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.
It should have the constructor:
public LifeDrainer(int hitProb, int damage)
and any other methods you think are necessary.
Submitting your code
These are just example instructions. Do NOT submit your answers to these sample questions.
You will be submitting your solutions online in the same way you submitted your assignments:
- Select “Create Jar File…” In the Project menu in BlueJ.
- In the dialog box make sure the “Include source” box is checked.
- Press Continue
- Save with the filename “q1.jar“, “q2.jar“, or “q3.jar” for questions 1, 2 and 3 respectively.
- Go to https://cgi.cse.unsw.edu.au/~give/Student/give.php
- Login with your CSE username and password
- Type COMP1400 in the Course field and press Search
- Select prac_exam_q1, prac_exam_q2, or prac_exam_q3 from the list of assignments and press Upload my assignment
- Select Browse to locate your q[123].jar file.
- Press Submit my files.
- Check the response to make sure your submission was processed correctly.
NOTE: You can submit as often as you like. Only the last submission will be marked. Do NOT leave it to the last minute. Submit each question as you go. Marks will be awarded for partial solutions, so always try to submit something even if it doesn’t work.
No Comments so far ↓
There are no comments yet...Kick things off by filling out the form below.
You must log in to post a comment.