Overview
if ((val % this.div) == 0) { return true; } else { return false; }
Write return (val % this.div) == 0;
C
implements I
, you cannot assign a value of type
Box<C>
to a variable of type Box<I>
.csc207-01-grader@grinnell.edu
Be good. Be well. Be true to yourself.
Get consent.
Remember that the debugger is your friend!
Things you will likely want to fix/update, particularly as you implement wrap-around.
this.back()
. See below for a thought question.this.front
in the range 0..this.values.length
-1. See
below for some notes.isFull()
method.if (this.front is 5) and
(this.size is 6) and
(this.values.length is 8)
what should this.back() return?
Ways to handle wrap-around with this.front
this.front % this.values.length
this.front
, mod by this.values.length
.Sam thinks strategy two is much better.
Here’s an example about testing for exceptions from
the JUnit 5 User Guide.
It uses a feature that you don’t quite know yet (the () ->
), but just
assume it’s necessary syntax and we’ll go from there.
@Test
void exceptionTesting() {
Exception exception = assertThrows(ArithmeticException.class, () ->
calculator.divide(1, 0));
assertEquals("/ by zero", exception.getMessage());
}
Here’s how Sam traditionally tests for exceptions.
@Test
void testException() {
try {
calculator.divide(1,0);
fail("Division did not throw an exception");
} catch (ArithmeticException ae) {
assertEquals("/ by zero", ae.getMessage());
} // try/catch
} // testException