Closed BaerbelW closed 2 years ago
The beauty of TDD is, the unit tests are already available and you can always analyse the expected behaviour for any method. I would suggest, you have a thorough look on the unit tests.
Apart from that, you could prepare your solution based on the following pointers.
Method Constructor: This method would be triggered at the time of instantiation of the object. As you can see it has two importing parameters minutes and hours. So, in a way, you need to store this information to capture what is the current time based on the parameters received.
Say, the parameters are 12(hour) and 30(minutes). So the current time is 12:30
Method add: It has an importing parameter “minutes”. So you need to add the minutes to the stored value on your clock. Say, the minutes is supplied as 90, then you need to add 90 to 12:30 and the new value for your clock becomes 14:00.
Method sub: Same as add, but you need to subtract the minutes from current clock time.
Method get: This method should be able to return the current time of your clock taking into account if any addition or subtraction is done after instantiation.
Thanks, @shafiq2601! I'll check this out in more detail over the weekend. I'm fairly certain that I'm making this more complex than it needs to be and then getting ever more confused!
I tried again but I don't have much of a clue of what all needs to go into this to make the tests pass (and I found the issue you raised about this exercise, Shafiq, but I only follow the gist of what your code is supposed to do). I'd really need to see a working solution which solves this in an easy to follow way to be able to come up with something workable myself. So, I'll just shelve this for now.
I however wish that mentoring were available while working on an exercise as opposed to only becoming availble once all tests pass. This for me would really help the learning experience (and keep frustrations at ones own limitations in check!). Is this perhaps something for Exercism to think about @ErikSchierboom?
@BaerbelW When creating an object instance you need to store the supplied values you receive in the constructor in an attribute. The get
method must return this attribute. ABAP's time data type makes this exercise very easy.
On a general note, the Exercism tracks also have a "learning mode" which includes individual "concepts", but they are a lot of work and we haven't done them for ABAP (yet!). Look at the tracks which have the learning mode
tag https://exercism.org/tracks
Open one of these and you'll see a Syllabus
link at the top next to Exercises
, you can browse any track's syllabus. The idea is that exercises get unlocked based on which concepts you've already learnt - I'm doing the Javascript track myself and clock is not available because I haven't completed Classes yet. To give you an idea of what it looks like, here's my JavaScript status:
The lightbulbs are concept exercises which will then unlock some of the others.
In relation to the clock exercise, have a look at the C# Classes
concept, it's not a million miles away from ABAP - what we call attributes
they call fields
, but otherwise the concepts and even syntax are pretty close.
https://exercism.org/tracks/csharp/concepts/classes
I wouldn't mind your feedback if you think the C# page helps, it's roughly what I'd base the ABAP one on.
Edit: Actually the Swift concept is even closer to ABAP, have a look at that one too.
https://exercism.org/tracks/swift/concepts/classes
Note that where we use ->
in ABAP, many other languages use .
, so myobj->something
would be myobj.something
in C, JS and Swift.
@pokrakam Thanks, Mike! But I'm getting more confused by the minute (pun intended) and looking at other languages will just add to my confusion, I'm afraid! I'll have to wait until I have a SAP-system with debugging available sometime next week to actually see what is happening while the tests are executed and what the various variables contain during the execution. Right now, I have a hard time picturing what is actually happening in which sequence when the tests run.
I suggested the other tracks for the content, not for the language, please have a look at swift or java (not javascript!) class
concepts, as they include a lot of background info on transitioning to OO. The ideas behind them is exactly the same as in ABAP - it was Java/C that provide the conceptual basis for OO-ABAP.
Here's a hint in a report format. The start-of-selection
section does what the unit tests do, except they use assert
s to verify the result instead of write
to output it.
REPORT zmptest.
PARAMETERS p_num TYPE i.
CLASS memoriser DEFINITION.
PUBLIC SECTION.
METHODS constructor IMPORTING i_num TYPE i.
METHODS get RETURNING VALUE(result) TYPE i.
PRIVATE SECTION.
DATA my_number type i.
ENDCLASS.
CLASS memoriser IMPLEMENTATION.
METHOD constructor.
my_number = i_num.
ENDMETHOD.
METHOD get.
result = my_number.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA(mem) = NEW memoriser( p_num ). "<-- NEW calls constructor, if implemented
WRITE / mem->get( ). "<--- what was entered
Thanks again, Mike! This is the part I actually do get in the exercise and I manage to have the GET-method put out what gets fed in via the CONSTRUCTOR. Where things "fall apart" for me is trying to figure out how to actually do the addition/subtraction in the other two methods and which variable types I need to use. At a guess, this would (for me) be a lot easier to understand if the incoming paramaters actually were one for time (formatted as hh:mm and interpretable as type t) and then another for minutes to add or subtract (type i). I'm getting confused with the typing and not being able to see what is actually happening with the formats and field content.
I however wish that mentoring were available while working on an exercise as opposed to only becoming availble once all tests pass. This for me would really help the learning experience (and keep frustrations at ones own limitations in check!). Is this perhaps something for Exercism to think about @ErikSchierboom?
Yeah, this is something we've considered and so far have decided not to implement. We'll discuss this to see if we want to change this in the future.
I however wish that mentoring were available while working on an exercise as opposed to only becoming availble once all tests pass
For context, the reason we don't do this is that if we did, it would almost certainly overwhelm our mentors immediately with people who get stuck on exercises, and then not allow them to do the type of mentoring that things are designed for. We have plans to overcome this issue, but it's not a simple problem to fix.
@ErikSchierboom & @iHiD Hi Erik, hi Jeremy, I understand. Could setting up a kind of user forum help, where we can help each other when we get stuck? Something like we have here on Github to raise technical issues for which it works nicely, but isn't really intended for the type of question I "abused" it for with this thread?
@BaerbelW What makes ABAP well suited for this exercise is that a type t
is stored as a readable type c
with length 6 but when used in numeric expressions it performs calculations in seconds. Same as with date.
So for example let's set a time of 10:30 and add 5 minutes:
data(time) = value t( '103000' ).
time += 300. " 5 * 60 seconds, time is now '103500'
write time. "--> 10:35:00
What makes this exercise a little 'special' is that formatting without seconds means you need to do it manually. Since time is a character field, string templates is your friend here:
result = |{ time(2) }:{ time+2(2) }|.
@BaerbelW did above help, can the issue be closed?
@larshp - IIRC, I found a workaroud and got it to work eventually. Sorry for not closing this earlier.
Cheers Bärbel
I realize that this is not a technical but a "PEBCAK" issue, but I wasn't sure where else to raise it, so I'm trying here. Please let me know if there's a better way to ask for help while working on an exercise!
I started to tackle the "CLOCK" exercise but am mystified where what type of code needs to be added. This is at least in parts due to the starting point of the code looking different compared to the eight exercises I already solved where each of the methods did have a returning parameter which is not the case here. Given that I'm still not well-versed with ABAP-OO, I'm for example wondering what needs to be put into the CONSTRUCTOR method and/or whether I need te create a new private method for some of the tasks.
For me, it would be helpful if I could already take a peek at other solutions to get a better idea of what I need to do - but the community solutions are of course not yet available as I haven't managed to pass all tests yet - a bit of a catch22. Perhaps the tips option could provide some pointers for me and (possibly) others?
Thanks and cheers Bärbel