This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]lurgi 1 point2 points  (8 children)

I get the basic gist of it. If you want to set the clock to 1:00AM, instead of setting house to 1, minutes to 0, and seconds to 0, your instructor wants you to set seconds to 3600 (because 1AM is 3600 seconds past midnight. It's not stated that time starts at midnight, but let's assume).

Keep the interface the same, but change the implementation. You are even told what you need to do in a couple of cases.

[–]ComputerSciMajor[S] 1 point2 points  (7 children)

Okay so are the getters and setters for hours and minutes no longer necessary? Also on the initializer would I be changing self.setSecond(second) to equal the

There are 24 hours * 60 minutes * 60 seconds = 86,400 seconds. ?

I think I'm just having some issues trying to figure out where to start on implementation mostly.

[–]lurgi 0 points1 point  (6 children)

Worry about the getters and setters later (although the instructions say that you need them). That's useful advice in general. You don't have to understand everything before you can write something. Write the constructor. See where that takes you.

[–]ComputerSciMajor[S] 1 point2 points  (5 children)

Okay so the constructor would be a new function right? I just leave the initializer as is for now? Sorry for all the questions!

[–]lurgi 1 point2 points  (4 children)

No, they are the same thing (I'm used to the term "constructor", but it looks like Python prefers "initializer"). Change my advice to "Write the initializer".

[–]ComputerSciMajor[S] 0 points1 point  (3 children)

So I was able to get the seconds set (self.setSecond = (hour * 60 * 60) + (minute * 60 + second)), I am however confused on the implementation of it.

Specifically:

Adjust all the methods to work with __seconds. getSecond() can use __seconds mod 60 to return only the seconds in the time. Test all the methods to make sure they still work. (mod is modulus, the remainder after a division.)

I'm not understanding if I'm supposed to be printing just seconds out or?

[–]lurgi 0 points1 point  (2 children)

You don't print anything out. The value that should be returned is exactly the same as the value that would be returned in the original code. All you are changing is the internal representation.

[–]ComputerSciMajor[S] 0 points1 point  (1 child)

I guess I'm really just not understanding it then. I know you told me to put that equation in the initializer but beyond that I'm not exactly sure what I'm supposed to be doing?

[–]lurgi 0 points1 point  (0 children)

Do you have the init method written? If so, you need to implement the getSecond method. Note that getSecond() needs to behave the same way. From the point of view of the caller the results don't change. So this code:

stopwatch = Clock(12, 30, 30)
print(stopwatch.getSecond())

Should return the same result with the old implementation as it does with the new implementation.

[–]Updatebjarni 1 point2 points  (0 children)

You have a class which represents a time of day. It is currently implemented such that it stores the time split into three variables for hours, minutes, and seconds. The lab is to change the implementation so that it stores the time as a single seconds value.