001package template.series4;
002
003interface Series {
004        void next();
005        void print();
006}
007class SeriesFactory {
008        private SeriesFactory() {}
009        public static Series newArith() { return new ArithSeries(); }
010        public static Series newGeom()  { return new GeomSeries(); }
011}
012abstract class AbstractSeries implements Series {
013        int x;
014        int y = 1;
015        public void next()  { x++; y = this.eval(y,2); }
016        public void print() { System.out.println("x=" + x + "; y=" + y); }
017
018        abstract protected int eval(int x, int y);
019}
020
021class ArithSeries extends AbstractSeries { protected int eval(int x, int y) { return x+y; } }
022class GeomSeries extends AbstractSeries { protected int eval(int x, int y) { return x*y; } }
023
024public class Main {
025        public static void main(String[] args) {
026                Series x = SeriesFactory.newGeom();
027                x.next();
028                x.next();
029                x.print();
030        }
031}