Create interface called Numbers, with a method intProcess(int x, int y),create class called Sum, in which the method Process finds the sum of two numbers and returns an int value. Write another class called Average, in which the Process method
CODING:
import java.util.Scanner;
interface Numbers{int process(int x,int y);}
class sum implements Numbers{
public int process(int x,int y){return (x+y);}
}
class average extends sum{
public int process(int x,int y){return ((x+y)/2);}
public static void main(String [] args){
int x,y;
average a1=new average();
sum s1=new sum();
Scanner n1=new Scanner(System.in);
System.out.print("Enter a Number:");
x=n1.nextInt();
System.out.print("Enter a Number:");
y=n1.nextInt();
System.out.println("Sum : "+s1.process(x,y));
System.out.println("Average : "+a1.process(x,y));
}
}
interface Numbers{int process(int x,int y);}
class sum implements Numbers{
public int process(int x,int y){return (x+y);}
}
class average extends sum{
public int process(int x,int y){return ((x+y)/2);}
public static void main(String [] args){
int x,y;
average a1=new average();
sum s1=new sum();
Scanner n1=new Scanner(System.in);
System.out.print("Enter a Number:");
x=n1.nextInt();
System.out.print("Enter a Number:");
y=n1.nextInt();
System.out.println("Sum : "+s1.process(x,y));
System.out.println("Average : "+a1.process(x,y));
}
}
Comments
Post a Comment