![]() |
![]() |
|
due Oct.25 (Fri) at the start of class.
Part B due Oct.28 (Mon) at the start of class
However, you should be able to complete it before the previous class starts
(bringing any questions to lecture/lab/office-hours/discussion-board).
All methods should be
.
Take your solution to part A (or my posted solution), and re-write it in an object-oriented format:
).S
, but you can if you like.)this
Be sure to write a correct test for your function:
create a
A
name: a small nugget
name: a fancy pen
name: chocolate egg
description: Upon close inspection, the nugget glints of gold!
weight: 0.05 lbs
image-URL: https://collections.nmnh.si.edu/media/?irn=10246678
description: This pen can write in purple, green, and plaid.
weight: 0.1 lbs
image-URL:
description: The size of an ostrich egg, but made entirely of dark chocolate.
weight: 35 lbs
image-URL:
(6pts) Create a class with these fields.
Before each field,
include a short javadoc comment describing what each field holds (including units, if applicable).
Also, be sure that your class extends
).super
(4pts)
Write a function
As you begin each of the functions below,
start by writing a test-case and adding it to
(5pts) Make a named
constant1
prettytext-representation of the object, intended for end-users to read. For example,
(5pts)
Write a function
thisTreasand
thatTreasin that order), and returns a boolean: whether or not
(8pts) Write , but it feels a bit chintzy
is
inserted just before (that's 2 of the pts) the ending punctuation.
Although we will probably not be doing this for this class,
here is one way a
Include test cases and javadoc for each function you write. You can have all your tests in a single function (so that you can re-use the same variables/examples-of-data for all your tests). As always, write your tests and comments before writing the actual code; the comments will help you focus on what the method does. PIs have been instructed to not help you on a method, if you don't have those comments already written.
Here is some code to help get you started.
Note that
/** Run tests for all STreasure functions (besides the constructor).
*/
void testSTreasure() {
STreasure t1 = new STreasure( "fancy pen", "This pen can write in purple, green, and plaid.", 0.1, "" );
// Make at least two more examples.
// Have at least 1-2 additional tests per function.
assertEquals( toPrettyString(t1), "chocolate egg (35.0 lbs)" );
assertEquals( false, isLint(t1) );
assertEquals( false, isBetterThan(t1,t1) );
assertEquals( new STreasure( "fancy pen", "This pen can write in purple, green, and plaid, but it feels a bit chintzy.", 0.05, "" ),
counterfeit(t1) );
}
|
Put the answer to these questions in a block-comment at the end of your file.
01. class Glarkzle {
02.
03. int numFloobs;
04. String name;
05.
06. static final int MAX_ORDER_SIZE = 25;
07.
08. Glarkzle( int nfs, String nm ) {
09. this.numFloobs = nfs;
10. this.name = nm;
11. }
12.
13. static String placeOrder( Glarkzle g, int numOrdered ) {
14. |
andthis
. (After all, we already know from the signature that they're of typethat
is a reserved word in Java; we'll actually start using it soon. ↩this
This page licensed CC-BY 4.0 Ian Barland Page last generated | Please mail any suggestions (incl. typos, broken links) to ibarland |