![]() |
![]() |
|
home—info—archive—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs
There's a flea on the wing on the flyQ: If all we have is a variable sea, what is an expression to get the flea's name?
On the frog on the bump on the log
In the hole in the middle of the sea
Ocean sea; sea = /* We assume sea has already been initialized by somebody else... */ Region m; // Declare m. m = sea.getMiddle(); // Initialize m. Anomoly h = m.getHole(); // Declare and initialize h -- two steps in one. // YOUR CODE HERE |
The next sequence of problems refer to the provided classes PhoneNumber and ContactInfo.
public class PhoneNumber { private String areaCode; // Exactly 3 digits. private String exchange; // Exactly 3 digits. private String extension; // Exactly 4 digits. /** @return This PhoneNumber's area code. * You may abbreviate this "gAC()" */ public String getAreaCode() { return this.areaCode; } /** @return This PhoneNumber's exchange. * You may abbreviate this "gExch()" */ public String getExchange() { return this.exchange; } /** @return This PhoneNumber's extension * You may abbreviate this "gExt()" */ public String getExtension() { return this.extension; } /** Determine whether two PhoneNumbers represent the same phone. * @param * @return whether this PhoneNumber represents the same number as . */ equals( ) { // YOUR CODE HERE } } |
/** A class to organize the contact info for a person. */ public class ContactInfo { private String name; // You may abbreviate this "n" private PhoneNumber homeNumber; // You may abbreviate this "hN" private PhoneNumber workNumber; // You may abbreviate this "wN" /** @return the person's home phone number. * You may abbreviate this "gHN()" */ public PhoneNumber getHomeNumber() { return this.homeNumber; } /** @return the person's work phone number. * You may abbreviate this "gWN()" */ public PhoneNumber getWorkNumber() { return this.workNumber; } /** Are `this' and `other' ContactInfos for two co-workers? * @param other The other contactInfo to compare with this one. * @return whether `other' is a co-worker of `this'. */ public boolean isCoworkerOf( ContactInfo other ) { // YOUR CODE HERE (one line suffices) } } |
ContactInfo ci1 = new ContactInfo( /* ... details omitted ... */ ); ContactInfo ci2 = new ContactInfo( /* ... details omitted ... */ ); ContactInfo ci3 = ci1; |
In lab02b.html, we wrote code so that EmCees could make regular introductions, as well as spy-introductions. We'll take that code and modify it. (You can use the posted lab solution if you like.)
We will augment EmCees so that they have yet another way to make an introduction: When asked to String introduceSurprise(String first, String last), they will sometimes return regular introduction, and sometimes return a spy-introduction. But there is rhyme and reason to their method:
Also, this cycle only counts the number of times introduceSurprise has been called. How many times an EmCee is directly asked to introduce or introduceSpy has no effect on introduceSurprise. (That's another good thing to verify, with test cases.)
(15 pts) Due Mar.24 (Mon); Submit the html documentation and test-class for EmCee as usual. (You don't need to submit those for class Die, if you didn't change that class.)
Record test cases for introduceSurprise.
Note that you can't assert a specific answer for every fourth call (to a specific EmCee); just leave the "assert" checkbox blank.
You can always edit the khaki test-file yourself; it's regular java code. In particular, you might want to record one or two tests, and then copy/paste/edit so that the function actually makes six to eight tests.
(Notice that you won't convince your boss your function is correct, if you don't show him/her tests which call your method at least five times! And your boss is clever enough to wonder whether two separate EmCees actually have different cycles. What is a test which would give them confidence?)
So how do you write tests to verify
that every fourth call really does give a randomized answer?
Write a static method
showTeststestFourthSurprise4
which
Note that even though this is for part (b), you'll turn the entire code for this task, and you'll write this code yourself rather than having BlueJ record it for you. (This is actually consistent with the philosophy “for part (b), turn in all tests/docs of your class's methods”.)
(15 pts), due Mar.26 (Wed) in class.
Submit the code for EmCee, as usual.
(Don't submit any code for class Die unless you
modified that class.)
Implement introduceSurprise, so that all your test cases pass, and that when you call showTests multiple times, you get different answers displayed on the console.
One possible hint: As a quantity gets bigger and bigger, its remainder (%) mod 4 cycles through 0,1,2,3,0,1,2,3,0,1,….
Be sure not to repeat code!
This is a bit streamlined; a few things to note:2Every anomoly has a log? That's definitely a weird world being modeled! Similarly, saying that every bump contains a frog is also a bit bizarre. (That's why this problem is extra-credit.) ↩
3 If you want to add class Die to your current BlueJ project, you can Edit > Add Class from File... (or, of course, you make a new class and paste in the code from your lab.) There is no need to modify your existing class Die from lab. ↩
4 In order for the test-class to let you call the method, its name must start with the first four letters “test”. ↩
home—info—archive—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs
©2008, Ian Barland, Radford University Last modified 2008.Mar.26 (Wed) |
Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |
![]() |