Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author Jason
- */
- import java.time.LocalTime;
- interface Comparison {
- public boolean isGreater(LocalTime obj1, LocalTime obj2);
- public boolean isLess(LocalTime time1, LocalTime time2);
- public boolean isEqual(LocalTime time1, LocalTime time2);
- }
- class Compare implements Comparison {
- public boolean isGreater(LocalTime time1, LocalTime time2) {
- return (time1.compareTo(time2) > 0);
- }
- public boolean isLess(LocalTime time1, LocalTime time2) {
- return (time1.compareTo(time2) < 0);
- }
- public boolean isEqual(LocalTime time1, LocalTime time2) {
- return (time1.compareTo(time2) == 0);
- }
- }
- public class Main {
- public static void main(String[] args) {
- // Time Object 1
- LocalTime time_object1 = LocalTime.of(3, 30, 10);
- // Time Object 2
- LocalTime time_object2 = LocalTime.of(3, 30, 10);
- Compare cmp = new Compare();
- if (cmp.isGreater(time_object1, time_object2)) {
- System.out.println(time_object1 + " is greater than " + time_object2);
- } else if (cmp.isLess(time_object1, time_object2)) {
- System.out.println(time_object1 + " is less than " + time_object2);
- } else if (cmp.isEqual(time_object1, time_object2)) {
- System.out.println(time_object1 + " is equal to " + time_object2);
- }
- }
- }
Add Comment
Please, Sign In to add comment