# Written By: Arup Guha
# Translated By: Tyler Woodhull
# 6/1/2013
# Time.py
# Edited on 6/5/2024 for SI@UCF

class Time:
    
    hours = 0 # number of hours in the time object.
    minutes = 0 # number of minutes in the time object.

    # The constructor for the time object
    def __init__(self, m = 0, h = None):
        # If one parameter is given, then it is just the number of minutes
        if(h == None):
            self.hours = m // 60
            self.minutes = m % 60
        # Since both parameters are given, then we have the number of
        # hours and minutes
        else:
            self.hours = h
            self.minutes = m

    def getHours(self):
        return self.hours

    def getMinutes(self):
        return self.minutes

    def setHours(self, h):
        self.hours = h

    def setMinutes(self, m):
        self.minutes = m

    # Returns the number of minutes a Time object is.
    def totalMinutes(self):
        return 60 * self.hours + self.minutes

    # Returns true if the argument to the method is equal in Time to the
    # Time object the method is called on.
    def equals(self, time2):
        if(self.totalMinutes() == time2.totalMinutes()):
            return True

        else:
            return False

    # Returns true if the argument to the method is longer in Time to the
    # Time object the method is called on.
    def greaterThan(self, time2):
        if(self.totalMinutes() > time2.totalMinutes()):
            return True

        else:
            return False

    # Adds the Time of the argument with the object the method is called on
    # together and returns their sum as a Time object.
    def addTime(self, time2):
        mins = self.totalMinutes() + time2.totalMinutes()
        return Time(mins)

    # Returns the difference in Time between the argument and the object
    # the method is called on. A Time object is returned.
    def difference(self, time2):
        mins = abs(self.totalMinutes() - time2.totalMinutes())
        return Time(mins)

    # This method changes the current object so that it represents twice
    # the amount of time it used to.
    def doubleIt(self):
        myMinutes = self.totalMinutes() * 2
        self.hours = myMinutes // 60
        self.minutes = myMinutes % 60

    # Returns a new Time object that is twice as long as the current one.
    def doubleIt2(self):
        myMinutes = self.totalMinutes() * 2
        return Time(myMinutes)

    # Returns the difference between the current object and t, in minutes.
    def compareTo(self, time2):
        return self.totalMinutes() - time2.totalMinutes()

    # Prints out the time object in a regular digital format.
    # Note: This has a bug in it, where the printout looks
    # strange if the number of minutes is less than 10.
    def printOut(self):
        print(str(int(self.hours)) + ":" + str(int(self.minutes)))

    # Returns a string representation of the object.
    
    def __str__(self):
        return str(self.hours) + " hours and " + str(self.minutes) + " minutes"

# Test time objects with two runs.
def runexample():

    # Initial time for a half marathon
    h1 = int(input("How many hours for your first run?\n"))
    m1 = int(input("How many minutes for your first run?\n"))
    time1 = Time(m1, h1)
    print(time1)

    h2 = int(input("How many hours for your second run?\n"))
    m2 = int(input("How many minutes for your second run?\n"))
    time2 = Time(m2, h2)
    print(time2)

    # I improved on my run.
    if time2.compareTo(time1) < 0:

        # How much better I did.
        better = time1.difference(time2)
        print("I was faster by",better)

    # Oops I did worse. Print out by how much.
    else:
        worse = time2.difference(time1)
        print("I was slower by", worse)

# This example adds up the times of several tasks you need to do.
def taskexample():

    n = int(input("how many tasks to do today?\n"))

    # Time used so far.
    used = Time(0,0)

    # Go through n events.
    for i in range(n):

        # Gets this time.
        h = int(input("How many hours for task "+str(i+1)+"?\n"))
        m = int(input("How many minutes for task "+str(i+1)+"?\n"))

        # Create the object and add to our accumulator.
        newtime = Time(m, h)
        used = used.addTime(newtime)

    print("Need",used,"to complete all tasks.")


# Weird cooking example I came up with in 1999.
def cook():
    hoursBake = int(input("Enter how long it took to bake your dinner. Enter hours.\n"))
    minutesBake = int(input("Enter minutes.\n"))

    hoursNuke = int(input("Enter how long it took to nuke your dinner. Enter hours.\n"))
    minutesNuke = int(input("Enter minutes.\n"))

    bake = Time(minutesBake, hoursBake)
    nuke = Time(minutesNuke, hoursNuke)

    bake = bake.doubleIt2()

    if(bake.equals(nuke)):
        print("Baking and Microwaving this food take the same amount of time.")

    elif(bake.greaterThan(nuke)):
        temp = bake.difference(nuke)
        print("Microwaving will save you " + str(temp) + " amount of time.")

    else:
        temp = nuke.difference(bake)
        print("You are cooking some really weird stuff.")
        print("Baking will save you " + str(temp) + " amount of time.")


# Uncomment to test what you want.
'''
runexample()
taskexample()
cook()
'''
