-
Encode and decode
-
Create two strings, one for a username and one for a password. Concatenate them together, separated by a colon. Use a method from the Groovy JDK to convert the resulting String to a byte array. Then use the
encodeBase64
method on byte array to create an encoded string. -
Decode the string by using the
decodeBase64
method, and using the result as an argument to the String constructor. Use the split method to return the original username and password.
-
-
Sorting a list
Create a class called
Course
, with aString
attribute calledname
and anint
attribute calleddays
. Create a list of four course instances, where at least two have the same number of days. Sort the list by number of days. Then, sort the list by days, but when the days are equal, sort by name. -
Operator overloading
-
Create a class called
Money
with a doubleamount
and aString
currency
(like USD or EUR). Implement aplus
method that checks that the currencies are the same and, if so, returns a newMoney
instance with the sum of the amounts and the correct currency. Write a similarminus
method. -
Write a
MoneyTest
class in Groovy that uses + and - and verifies that they work properly.
-