You are on page 1of 2

COLLEGE OF COMPUTER STUDEIS

INFORMATION TECHNOLOGY DEPARTMENT

CCS0023L
(Object Oriented Programming)

Machine Problem

7
How to implement polymorphism and inheritance

Student Name: Rodriguez, James J.


Section: 2-D
Professor: Ma’am Barrientos, Charmane Joy
Create an interface named Comparison whose method can be used to compare two
Time objects. The methods will include isGreater, isLess, and isEqual. Create
another class that will implement these methods.

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");
}
}
}

You might also like