equation1.java

来自「程序练习中包括书中实例程序代码和练习中要用到的代码,是压缩文件」· Java 代码 · 共 57 行

JAVA
57
字号
package examples.inner;

/** A class definition to explore the use of local
  * inner classes
  */
public class Equation1 {

   private int equationInput;

   /** An interface defining the result from an
     * equation
     */
   public interface Result {
      public double getAnswer();
   }

   /** Constructor method
     * @param ei the equation input
     */
   public Equation1( int ei ) {
      equationInput = ei;
   }

   /** Create the result of the equation for the given
     * input values
     * @param input1 the first equation input
     * @param input2 the second equation input
     * @return the result object
     */
   public Result getResult( final int input1,
                            final int input2 ) {
      final int [] localVar = { 2,6,10,14};
      class MyResult implements Result {
         private int normalField;

         public MyResult() {
            normalField = 2;
         }
         public double getAnswer() {
           return (double) input1 / input2
                           - equationInput
                           + localVar[2]
                           - normalField;
         }
      }
      return new MyResult();
   }

   /** The test method for the class
     * @param args not used
     */
   public static void main( String[] args ) {
      Equation1 e = new Equation1( 10 );
      Result r = e.getResult( 33, 5 );
      System.out.println( r.getAnswer() );
   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?