diff --git a/cs172/Lect03/EL.py b/cs172/Lect03/EL.py new file mode 100644 index 0000000000000000000000000000000000000000..90629ae5a6845da962aaaf3b9f32adc9a7becfe2 --- /dev/null +++ b/cs172/Lect03/EL.py @@ -0,0 +1,59 @@ + +class EL: + + def __init__(self, inches=0, feet=0, yards=0): + self.__inches = inches % 12 + self.__feet = feet + inches // 12 + self.__yards = yards + self.__feet // 3 + self.__feet = self.__feet % 3 + + def getInches(self): + return self.__inches + + def getFeet(self): + return self.__feet + + def getYards(self): + return self.__yards + + def totalInches(self): + return self.__inches + self.__feet * 12 + self.__yards * 36 + + def addInches(self, additionalInches): + newTotalInches = self.totalInches() + additionalInches + tempLength = EL(newTotalInches) + self.__yards = tempLength.getYards() + self.__feet = tempLength.getFeet() + self.__inches = tempLength.getInches() + + def __add__(self, otherEL): + newEL = EL(self.totalInches() + otherEL.totalInches()) + return newEL + +if __name__ == "__main__": + len1 = EL(39) + print(len1.getInches(), "inches") + print(len1.getFeet(), "feet") + print(len1.getYards(), "yards") + print(len1.totalInches(), "inches total") + + print("Adding 20 inches...") + len1.addInches(20) + + print(len1.getInches(), "inches") + print(len1.getFeet(), "feet") + print(len1.getYards(), "yards") + print(len1.totalInches(), "inches total") + + print("Making 2 EL objects to add together") + lenA = EL(11) + lenB = EL(9) + + lenC = lenA + lenB + + print(lenC.getInches(), "inches") + print(lenC.getFeet(), "feet") + print(lenC.getYards(), "yards") + print(lenC.totalInches(), "inches total") + + \ No newline at end of file diff --git a/cs172/Lect03/demo.py b/cs172/Lect03/demo.py new file mode 100644 index 0000000000000000000000000000000000000000..97f6ed454592919d4b52810cb641d32d1d0a4f3d --- /dev/null +++ b/cs172/Lect03/demo.py @@ -0,0 +1,18 @@ + +import lect3 + +a = lect3.Clock() +b = lect3.Clock() + +a.setTime(10, 10) + +b.setTime(1, 7) + +print(b.getTime()) + +left = 22 +right = 7 + +print(left + right) + +print(a + b) \ No newline at end of file diff --git a/cs172/Lect03/lect3.py b/cs172/Lect03/lect3.py new file mode 100644 index 0000000000000000000000000000000000000000..dcb37e9cafef841f325f4340c7a351348059d52f --- /dev/null +++ b/cs172/Lect03/lect3.py @@ -0,0 +1,34 @@ + +import math + +class Clock: + + def __init__(self): + self.__hours = 12 + self.__minutes = 0 + + def getHours(self): + return self.__hours + + def getMinutes(self): + return self.__minutes + + def getTime(self): + return f"{self.__hours}:{str(self.__minutes).zfill(2)}" + + def setTime(self, newHours, newMinutes): + self.__hours = abs(newHours) % 13 + self.__minutes = abs(newMinutes) % 60 + + #TODO: Fix this math + def nextMinute(self): + self.__minutes += 1 + if self.__minutes > 59: + self.__minutes = 0 + self.__hours += 1 + self.__hours = self.__hours % 13 + +if __name__ == "__main__": + myClock = Clock() + myClock.setTime(10, 2) + print(myClock.getTime()) diff --git a/cs172/Lect03/new.py b/cs172/Lect03/new.py new file mode 100644 index 0000000000000000000000000000000000000000..8f04655002bdf3fcf786cc23f9286f9971e38db2 --- /dev/null +++ b/cs172/Lect03/new.py @@ -0,0 +1,7 @@ + +import old + +print("This code is in the new file") + +old.main() +old.printHappyFace() \ No newline at end of file diff --git a/cs172/Lect03/old.py b/cs172/Lect03/old.py new file mode 100644 index 0000000000000000000000000000000000000000..68535134852d83b7f0f4d07a8067adf30fe9ab10 --- /dev/null +++ b/cs172/Lect03/old.py @@ -0,0 +1,10 @@ + +def main(): + print("This code is in the old file") + +def printHappyFace(): + print("😘") + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/cs172/Lect03/starter_code.py b/cs172/Lect03/starter_code.py new file mode 100644 index 0000000000000000000000000000000000000000..52fa0dea9739d47301a6fc438b0396a2de72c23c --- /dev/null +++ b/cs172/Lect03/starter_code.py @@ -0,0 +1,30 @@ +class EL: + + def __init__(self, inches=0, feet=0, yards=0): + self.__inches = inches % 12 + self.__feet = feet + inches // 12 + self.__yards = yards + self.__feet // 3 + self.__feet = self.__feet % 3 + + def getInches(self): + return self.__inches + + def getFeet(self): + return self.__feet + + def getYards(self): + return self.__yards + + def totalInches(self): + return self.__inches + self.__feet * 12 + self.__yards * 36 + + def addInches(self, additionalInches): + newTotalInches = self.totalInches() + additionalInches + tempLength = EL(newTotalInches) + self.__yards = tempLength.getYards() + self.__feet = tempLength.getFeet() + self.__inches = tempLength.getInches() + + def __add__(self, otherEL): + newEL = EL(self.totalInches() + otherEL.totalInches()) + return newEL \ No newline at end of file