Skip to content

Commit 3ba3f49

Browse files
committed
Ex completed
1 parent 2393224 commit 3ba3f49

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

src/main/java/com/booleanuk/core/Exercise.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class Exercise {
77
// 1. The brokenUrl member above contains an invalid URL. There's a z instead of an s in the protocol (httpz instead of https).
88
// Using the `replace` method on brokenUrl, set the fixedUrl member below to the correct value.
99
// https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/lang/String.html#replace(char,char)
10-
public String fixedUrl = "";
10+
public String fixedUrl = brokenUrl.replace('z', 's');
1111

1212

1313
// 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 {
1616

1717
// 2. There are currently some upper case characters in the URL. Using an appropriate string method on the fixedUrl member above,
1818
// set the value of lowerCasedUrl.
19-
public String lowerCasedUrl = "";
19+
public String lowerCasedUrl = fixedUrl.toLowerCase();
2020

2121

2222
// 3. There is still white space on both ends of the URL! Use the appropriate string method to trim that white space
2323
// and set the value of the url member below
24-
public String url = "";
24+
public String url = lowerCasedUrl.strip();
2525

2626

2727
// 4. Using the appropriate string method on url, set the value of the protocol member below
28-
public String protocol = "";
28+
public String protocol = url.substring(0, 5);
2929

3030

3131
// 5. Using the appropriate string method on url, set the value of the domain member below
32-
public String domain = "";
32+
public String domain = url.substring(8, 21);
3333

3434

3535
// 6. Set the length member below to the length of the url member
36-
public int length = 0;
36+
public int length = url.length();
3737

3838

3939
// 7. Using concatenation and existing members, set the faqUrl member below to the faq page of the boolean website
40-
public String faqUrl = "";
40+
public String faqUrl = url.substring(0, 22).concat("faq");
4141
}

src/main/java/com/booleanuk/extension/Extension.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ public StringBuilder one() {
2828

2929
// 1. Using the sb variable above, add "Hello, world!" to the StringBuilder
3030
// WRITE YOUR CODE BETWEEN THIS LINE...
31-
32-
33-
31+
sb.append("Hello, world!");
3432
// ...AND THIS LINE
3533

3634
return sb;
@@ -42,9 +40,8 @@ public StringBuilder two() {
4240
// 1. Using the sb variable above, add "Hello, world!" to the StringBuilder
4341
// 2. After adding the message, use an appropriate StringBuilder method to reverse it
4442
// WRITE YOUR CODE BETWEEN THIS LINE...
45-
46-
47-
43+
sb.append("Hello, world!");
44+
sb.reverse();
4845
// ...AND THIS LINE
4946

5047
return sb;
@@ -56,9 +53,8 @@ public StringBuilder three() {
5653
// 1. Using the sb variable above, add "Hello, world!" to the StringBuilder
5754
// 2. After adding the message, remove the comma.
5855
// WRITE YOUR CODE BETWEEN THIS LINE...
59-
60-
61-
56+
sb.append("Hello, world!");
57+
sb.deleteCharAt(sb.indexOf(","));
6258
// ...AND THIS LINE
6359

6460
return sb;
@@ -70,9 +66,8 @@ public StringBuilder four() {
7066
// 1. Using the sb variable above, add "Hello, world!" to the StringBuilder
7167
// 2. After adding the message, replace the word "world" with the word "Java"
7268
// WRITE YOUR CODE BETWEEN THIS LINE...
73-
74-
75-
69+
sb.append("Hello, world!");
70+
sb.replace(sb.indexOf("w"), sb.length() - 1, "Java");
7671
// ...AND THIS LINE
7772

7873
return sb;

0 commit comments

Comments
 (0)