CIS 17: Java Programming

Project E

Objective:

To create static factory methods, use them in lieu of constructors and upcast to an interface for the access of multiple implementations.
interface Tosser {/*...*/}

class Die implements Tosser {/*...*/}

class Coin implements Tosser {/*...*/}

class TossFactory {/*...*/}

public class TossGames {
  public static void main(String[] args) {
    Tosser t = TossFactory.getDie();
    t.toss(10);
    t = TossFactory.getCoin();
    t.toss(5); }
}
Three
Three
Three
Three
Four
One
Four
Two
One
Three

Heads
Tails
Tails
Tails
Heads

Submit your work via the CATE form for Project E.

Legend: method/function keyword literal

2007/03/28