Question
(I need help with this coding problem; an explanation would be appreciated. In Python, please, thank you.) Implement a class RollText which has an immutable
(I need help with this coding problem; an explanation would be appreciated. In Python, please, thank you.)
Implement a class RollText which has an immutable class parameter str of type String and the following methods:
get_str() : takes in no arguments, returns the string str (return type is String)
roll_str(): takes in no arguments, returns a new RollText instance whose member string is given by calling roll function on the current member string str. Return type is RollText.
reverse_str(): takes in no arguments, returns a new RollText instance whose member string is given by reversing the current member string str. Return type is RollText.
append_str(str_to_add: String): takes in an argument str_to_add and returns a new RollText whose member string appends str_to_add to the end of the current member string str. Return type is RollText.
length(): takes in no argument, returns the length of the string str. Return type is Int.
// YOUR CODE HERE ???
val r1 = new RollText("hello") val r1_str = r1.get_str() testWithMessage(r1_str, "hello", "Test 1")
val r2 = r1.roll_str() val r2_str = r2.get_str() testWithMessage(r2_str, "elloh", "Test 2")
val r3 = r2.roll_str() val r3_str = r3.get_str() testWithMessage(r3_str, "llohe", "Test 3")
val r4 = r3.reverse_str() val r4_str = r4.get_str() testWithMessage(r4_str, "eholl", "Test 4")
val r5 = r4.append_str("what") val r5_str = r5.get_str() testWithMessage(r5_str, "ehollwhat", "Test 5")
testWithMessage(r5.length(), 9, "Test 6")
passed(15)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started