Write Java programs as required:
(1) write an interface:interfacea, which contains only one method, int (int n);
(2) write a class:ClassA to implement the interface interfacea, implement the int method ( int n) interface Side
the calculation of 1 to n is required;
(3) write another class:ClassB to Implement Interface Interfacea, Implementing int method (int n) Interface
method is required to calculate the factorial of n (n! );
(4) write test class e, test the implementation using the form of an interface callback in the main method oftest class e
The class of the interface.
Package Pack1; Public Interface interfacea { int method (int n);}
package Pack1; public class ClassA implements Interfacea {@Override public int method (int N) { ; for (int I=0;i<=n;i++) {A +=i; return A; }}
package Pack1; public class ClassB implements Interfacea {@Override public int method (int N) { ; for (int I=1;i<=n;i++) {A *=i; return A; }}
Package Pack1; Public class E { publicstaticvoid main (string[] args) { interfacea A; A=new ClassA (); System.out.println (A.method (5)); A=new ClassB (); System.out.println (A.method (5));} }
Java Practice Writing Java programs as required: