From b3f3b055d386b190d43b22cfdd1e70d0990a749f Mon Sep 17 00:00:00 2001 From: Petros Mylonas Date: Wed, 10 Jan 2024 15:37:45 +0200 Subject: [PATCH] Petros mylonas --- .../java/com/booleanuk/core/Exercise.java | 46 ++++++++++--------- .../com/booleanuk/extension/Extension.java | 14 +++--- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/booleanuk/core/Exercise.java b/src/main/java/com/booleanuk/core/Exercise.java index 5b1fe79..89cf1f6 100644 --- a/src/main/java/com/booleanuk/core/Exercise.java +++ b/src/main/java/com/booleanuk/core/Exercise.java @@ -1,41 +1,43 @@ package com.booleanuk.core; public class Exercise { - // A URL consists of these parts: [protocol]://[domain]/[path] - public String brokenUrl = " httpz://booLeAn.co.uk/who-we-are "; - // 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 = ""; + // A URL consists of these parts: [protocol]://[domain]/[path] + public String brokenUrl = " httpz://booLeAn.co.uk/who-we-are "; + // 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 =brokenUrl.replace('z', 's'); - // Here's a documentation link for all string methods, use it to figure out how to complete the rest of these requirements: - // https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/lang/String.html#method-summary + // Here's a documentation link for all string methods, use it to figure out how to complete the rest of these requirements: + // https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/lang/String.html#method-summary - // 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 = ""; + // 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 = 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 = ""; + // 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 = lowerCasedUrl.replaceAll(" ",""); - // 4. Using the appropriate string method on url, set the value of the protocol member below - public String protocol = ""; + // 4. Using the appropriate string method on url, set the value of the protocol member below + public String protocol = url.substring(0,5); - // 5. Using the appropriate string method on url, set the value of the domain member below - public String domain = ""; + // 5. Using the appropriate string method on url, set the value of the domain member below + public String domain = url.substring(8,21); - // 6. Set the length member below to the length of the url member - public int length = 0; + // 6. Set the length member below to the length of the url member + 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 = url.substring(0,21).concat("/faq"); - // 7. Using concatenation and existing members, set the faqUrl member below to the faq page of the boolean website - public String faqUrl = ""; } diff --git a/src/main/java/com/booleanuk/extension/Extension.java b/src/main/java/com/booleanuk/extension/Extension.java index 5f84cdb..b38709f 100644 --- a/src/main/java/com/booleanuk/extension/Extension.java +++ b/src/main/java/com/booleanuk/extension/Extension.java @@ -28,7 +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 @@ -42,8 +42,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 @@ -56,8 +56,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.deleteCharAt(5); // ...AND THIS LINE @@ -71,8 +71,8 @@ public StringBuilder four() { // 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(7,12,"Java"); // ...AND THIS LINE return sb;