From c851c2541edc86f43fd9c2fac906c40e3750b1e0 Mon Sep 17 00:00:00 2001 From: Magnus Hissingby Date: Tue, 5 Aug 2025 16:02:43 +0200 Subject: [PATCH 1/2] Exercise --- src/main/java/com/booleanuk/core/Exercise.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/booleanuk/core/Exercise.java b/src/main/java/com/booleanuk/core/Exercise.java index 5b1fe79..4fcffea 100644 --- a/src/main/java/com/booleanuk/core/Exercise.java +++ b/src/main/java/com/booleanuk/core/Exercise.java @@ -7,7 +7,7 @@ public class Exercise { // 1. The brokenUrl member above contains an invalid URL. There's a z instead of an s in the protocol (httpz instead of https). // Using the `replace` method on brokenUrl, set the fixedUrl member below to the correct value. // https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/lang/String.html#replace(char,char) - public String fixedUrl = ""; + public String fixedUrl = brokenUrl.replace("httpz", "https"); // Here's a documentation link for all string methods, use it to figure out how to complete the rest of these requirements: @@ -16,26 +16,26 @@ public class Exercise { // 2. There are currently some upper case characters in the URL. Using an appropriate string method on the fixedUrl member above, // set the value of lowerCasedUrl. - public String lowerCasedUrl = ""; + public String lowerCasedUrl = fixedUrl.toLowerCase(); // 3. There is still white space on both ends of the URL! Use the appropriate string method to trim that white space // and set the value of the url member below - public String url = ""; + public String url = lowerCasedUrl.strip(); // 4. Using the appropriate string method on url, set the value of the protocol member below - public String protocol = ""; + public String protocol = url.split("://")[0]; // 5. Using the appropriate string method on url, set the value of the domain member below - public String domain = ""; + public String domain = url.split("://")[1].replace("/who-we-are", ""); // 6. Set the length member below to the length of the url member - public int length = 0; + public int length = url.length(); // 7. Using concatenation and existing members, set the faqUrl member below to the faq page of the boolean website - public String faqUrl = ""; + public String faqUrl = protocol + "://" + domain.replace("who-we-are", "faq") + "/faq" ; } From 0529d0e553bd299ad7c9de1bc9d48ff6a540a263 Mon Sep 17 00:00:00 2001 From: Magnus Hissingby Date: Wed, 6 Aug 2025 09:13:39 +0200 Subject: [PATCH 2/2] Exercise --- .../com/booleanuk/extension/Extension.java | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/booleanuk/extension/Extension.java b/src/main/java/com/booleanuk/extension/Extension.java index 5f84cdb..462dc92 100644 --- a/src/main/java/com/booleanuk/extension/Extension.java +++ b/src/main/java/com/booleanuk/extension/Extension.java @@ -28,9 +28,7 @@ public StringBuilder one() { // 1. Using the sb variable above, add "Hello, world!" to the StringBuilder // WRITE YOUR CODE BETWEEN THIS LINE... - - - + sb.append("Hello, world!"); // ...AND THIS LINE return sb; @@ -42,9 +40,8 @@ public StringBuilder two() { // 1. Using the sb variable above, add "Hello, world!" to the StringBuilder // 2. After adding the message, use an appropriate StringBuilder method to reverse it // WRITE YOUR CODE BETWEEN THIS LINE... - - - + sb.append("Hello, world!"); + sb.reverse(); // ...AND THIS LINE return sb; @@ -56,9 +53,8 @@ public StringBuilder three() { // 1. Using the sb variable above, add "Hello, world!" to the StringBuilder // 2. After adding the message, remove the comma. // WRITE YOUR CODE BETWEEN THIS LINE... - - - + sb.append("Hello, world!"); + sb.replace(sb.indexOf("o"), sb.indexOf("w"), "o "); // ...AND THIS LINE return sb; @@ -70,9 +66,8 @@ public StringBuilder four() { // 1. Using the sb variable above, add "Hello, world!" to the StringBuilder // 2. After adding the message, replace the word "world" with the word "Java" // WRITE YOUR CODE BETWEEN THIS LINE... - - - + sb.append("Hello, world!"); + sb.replace(sb.indexOf("w"), sb.indexOf("!"), "Java"); // ...AND THIS LINE return sb;