enum枚举

public enum Planet {

      SUN(12,34){ 

            public int plus(int a,int b){return a + b + 100;} 

            public int devide(int a,int b){return b / a;}

      },

      MOON(34,56){

            public int plus(int a,int b){return a + b - 12;} 

            public int devide(int a,int b){return b / a + 5;}

      };

      

      private int a;

      private int b;

      

      private Planet(int a,int b){

            this.a = a;

            this.b = b;

            

      }

      public abstract int plus(int a,int b);

      

      public int minus(){

            return b - a;

      }

      

      public int times(){

            return a * b;

      }

      

      public abstract int devide(int a,int b);

      

      public int getA() {

            return a;

      }

      public void setA(int a) {

            this.a = a;

      }

      public int getB() {

            return b;

      }

      public void setB(int b) {

            this.b = b;

      }

      

      public static void main(String[] args) {

            for(Planet p : Planet.values()){

                  int t = p.plus(p.getA(), p.getB());

                  System.out.print(p);

                  System.out.print("," + t);

                  System.out.print("," + p.minus());

                  System.out.println("," + p.devide(p.getA(), p.getB()));

            }

      }

}

你可能感兴趣的:(sun)