Overview
if ((val % this.div) == 0) { return true; } else { return fal
se; }
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>
.import java.lang.String;
at the top of your file.
Copying to another project also works in some cases.csc207-01-grader@grinnell.edu
Be good. Be well. Be true to yourself.
Consent is essential.
I’m going to try to skip questions today so that there’s enough time for lab.
How should we partner on a GitHub repo?
Normal 207 practice vs. Normal “experienced” practice
Normal 207 practice: When I stop, push everything to the repo. When I start again, pull from the repo. Issue: If you push stuff that doesn’t work, no one has working code.
Better practice: If you’ve done work that you don’t want to push to the main branch, but don’t want to lose, you can create another branch.
You could also use forks, but that could be a bit more complicated.
The debugger is your friend! (or it can be your friend)
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
Note that you may note necessarily want to check the particular text of the exception.