01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package template.series1;

interface Series {
  void next();
  void print();
}
class SeriesFactory {
  private SeriesFactory() {}
  public static Series newArith() { return new ArithSeries(); }
  public static Series newGeom()  { return new GeomSeries(); }
}
class ArithSeries implements Series {
  int x;
  int y = 1;
  public void next()  { x++; y = y+2; }
  public void print() { System.out.println("x=" + x + "; y=" + y); }
}
class GeomSeries implements Series {
  int x;
  int y = 1;
  public void next()  { x++; y = y*2; }
  public void print() { System.out.println("x=" + x + "; y=" + y); }
}

public class Main {
  public static void main(String[] args) {
    Series x = SeriesFactory.newGeom();
    x.next();
    x.next();
    x.print();
  }
}