|
Assignment 21
Task
Recreate a missing class from specifications.
Concepts: Practice with arrays, exceptions, writing classes, as well as reading and creating javadoc pages and working as part of a larger project.
Textbook: 10.5
Scenario
It's a quiet Wednesday afternoon at your job at Exitech when your boss dashes up to your cubicle, hair and tie in disarray:
We can't find Henry! And one of his files is missing from the server! I need you to rewrite it, quick!
See, we're working with this small independent gaming company and they want to produce some simple web-based shooting games with a focus on resource management. So Henry wrote this pistol class for them to reuse, and then a proof-of-concept game with vampires or something to show how it could be used. We've got the game, the testing classes, all the documentation... but the gun file's missing, and so nothing works!
I'll get Pam to forward what we have left. I need that class written by tomorrow morning!
Your boss dashes off before you can ask any questions. Ugh... not again!
A few minutes later, you recieve the following files from Pam:
And a link to this documentation.
Steps
Reconstruct the Revolver class. The documentation should tell you what it does, and the RevolverTest should pass all tests when you're done. (You can copy and paste the documentation text to reconstruct the javadocs.)
Once RevovlerTest is working, you shouldn't have to touch ZombieHallway.
When you're done, rename Revolver.java to UsernameA21.java and submit it.
Hints
What to Submit
Upload your UsernameA21.java file to Tamarin.
Grading [6 points]
- 1 - Compiles + Coding Standards
- Your program compiles successfully (no errors). Your code follows Java coding standards.
- 4.4 - Constructor and 9 methods
- Each member works as described, with the given method signature, returning the correct values or throwing the specified exceptions when appropriate. (0.5 each; except
open , close , and isOpen , which are 0.3 each).
- 0.6 - Encapsulation
- All instance variables are private.
FAQs
- How do I throw the exceptions? Does that happen automatically?
- You need to explicitly test whether the exception should be thrown and then construct a new excption object and throw it.
So, for example, assume you're using a private boolean instance variable open to track whether the gun is currently open or closed. At the start of your fire() method, you could use this code:
if (this.open) {
throw new IllegalStateException("Cannot fire an open gun.");
}
//if made it this far, gun is closed, so put the rest of your fire() code here
The excpetion message is optional, so you could just have this instead: throw new IllegalStateException();
|