Professional Documents
Culture Documents
CCS0023L
(Object Oriented Programming)
Machine Problem
7
How to implement polymorphism and inheritance
CODE:
import java.util.Scanner;
interface Comparison{
boolean isGreater(long xTime, long yTime);
boolean isLess(long xTime, long yTime);
boolean isEqual(long xTime, long yTime);
}
class TimeCalcu implements Comparison{
public boolean isGreater(long xTime, long yTime){
if(xTime > yTime){
return true;
}
else{
return false;
}
}
public boolean isLess(long xTime, long yTime){
if(xTime < yTime){
return true;
}
else{
return false;
}
}
public boolean isEqual(long xTime, long yTime){
if(xTime == yTime){
return true;
}
else{
return false;
}
}
}
public class Interface{
public static void main(String[]args){
Scanner input = new Scanner(System.in);
TimeCalcu newTime = new TimeCalcu();
System.out.println("1st number" );
long x = input.nextLong();
System.out.println("2nd number:");
long y = input.nextLong();
if (newTime.isGreater(x,y)){
System.out.println("Greater")
}
else if (newTime.isLess(x,y)){
System.out.println("Less");
}
else if (newTime.isEqual(x,y)){
System.out.println("Equal");
}
else{
System.out.println("no input");
}
}
}