Practice with interfaces and implementing them.
OnToInterfaces
project inside Eclipse. Use the SVN Repository Exploring
perspective to check out this project, then switch back to the Java
perspective.
TODO
items in polygon.Polygon
.
LinearCharge
class that implements the Charge
interface.
ChargeMain
that adds some LinearCharge
instances to the Space
.
Board Game: Begin the board game exercise described in Project 9.2 in Big Java (p. 435). Decide what methods your Game
interface should have. Add these methods signatures—remember, methods in interfaces do not have bodies—to the Game
interface provided in the boardGames
package of today’s Eclipse project. Write javadoc comments for your methods.
Despite what the last paragraph says in the text, you do not have to provide implementations of your interface yet. However, you should be prepared to describe your interface design to the class in our next meeting. Don’t feel like you have to get this design perfect; we’ll refine the design together in class.
BigInteger
class, which we’ve used before. Do you recall what its use is? Why not just use int
s?
Comparable
interface and figure out what it is all about. What method(s) must a class implement if it implements Comparable
?
BigInteger
class should reveal a method that will save you some time here.
BigRational
is an immutable class. Each math method should return a brand new object, leaving the operands untouched.
equals()
and toString()
methods. Your implementation of toString()
should be simple—just display in the form a/b—but be sure to display the reduced form of the fraction. Examples:
BasicBigRationalTest
and LargeBigRationalTest
. You can run both by right-clicking the bigRational
package and choosing Run As → JUnit test.
throw new ArithmeticException("Divide by zero");
Turn in your programming work by committing it to your SVN repository.