With RatingServerInterface
defined in Segment 1022, and
MovieInterface
defined in Segment 1021, you can make
the following changes in the evolving RatingServer
and
ClientStub
classes. Note that both a parameter and a variable are
typed by interface names, rather than by class names:
import java.rmi.*; public class RatingServer implements RatingServerInterface { public int serverRating (MovieInterface m) throws RemoteException { System.out.println("RatingServer asked for a rating"); int s = m.getScript(); int a = m.getActing(); int d = m.getDirection(); return 3 * Math.max(Math.max(s, a), d); } }
import java.rmi.*;
import java.math.*;
public class ClientStub {
public static void main(String args[]) throws RemoteException {
// Construct a movie for testing
Movie movie = new Movie(2, 3, 8, "Psycho");
// Construct a rating server for testing
RatingServerInterface ratingServer = new RatingServer();
// Test and print
int rating = ratingServer.serverRating(movie);
System.out.println("The server returned " + rating);
}
}