Skip to content

Commit b89fcf2

Browse files
committed
add exercise
1 parent 44c5a4d commit b89fcf2

File tree

6 files changed

+91
-24
lines changed

6 files changed

+91
-24
lines changed

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
# Java Exercise Template
2-
3-
This template contains a `Sample` class and a `SampleTest` class. When making changes, ensure you change the project
4-
name in the [settings.gradle](./settings.gradle) file.
1+
# Java Strings
52

63
## Learning Objectives
7-
- Sample learning objective
4+
- Use common Java string operations to manipulate a URL
85

96
## Set up instructions
107
- Fork this repository and clone the forked version to your machine

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
rootProject.name = 'java.template'
1+
rootProject.name = 'java.fundamentals.strings'
22

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.booleanuk;
2+
3+
public class Exercise {
4+
// A URL consists of these parts: [protocol]://[domain]/[path]
5+
public String brokenUrl = " httpz://booLeAn.co.uk/who-we-are ";
6+
7+
// 1. The brokenUrl member above contains an invalid URL. There's a z instead of an s in the protocol (httpz instead of https).
8+
// Using the `replace` method on brokenUrl, set the fixedUrl member below to the correct value.
9+
// https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/lang/String.html#replace(char,char)
10+
public String fixedUrl = "";
11+
12+
13+
// Here's a documentation link for all string methods, use it to figure out how to complete the rest of these requirements:
14+
// https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/lang/String.html#method-summary
15+
16+
17+
// 2. There are currently some upper case characters in the URL. Using an appropriate string method on the fixedUrl member above,
18+
// set the value of lowerCasedUrl.
19+
public String lowerCasedUrl = "";
20+
21+
22+
// 3. There is still white space on both ends of the URL! Use the appropriate string method to trim that white space
23+
// and set the value of the url member below
24+
public String url = "";
25+
26+
27+
// 4. Using the appropriate string method on url, set the value of the protocol member below
28+
public String protocol = "";
29+
30+
31+
// 5. Using the appropriate string method on url, set the value of the domain member below
32+
public String domain = "";
33+
34+
35+
// 6. Set the length member below to the length of the url member
36+
public int length = 0;
37+
38+
39+
// 7. Using concatenation and existing members, set the faqUrl member below to the faq page of the boolean website
40+
public String faqUrl = "";
41+
}

src/main/java/com/booleanuk/Sample.java

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.booleanuk;
2+
3+
import org.junit.jupiter.api.Assertions;
4+
import org.junit.jupiter.api.Test;
5+
6+
class ExerciseTest {
7+
Exercise exercise;
8+
9+
public ExerciseTest() {
10+
this.exercise = new Exercise();
11+
}
12+
13+
@Test
14+
public void urlShouldBeFixed() {
15+
Assertions.assertEquals(" https://booLeAn.co.uk/who-we-are ", this.exercise.fixedUrl);
16+
}
17+
18+
@Test
19+
public void urlShouldBeLowerCase() {
20+
Assertions.assertEquals(" https://boolean.co.uk/who-we-are ", this.exercise.lowerCasedUrl);
21+
}
22+
23+
@Test
24+
public void urlShouldBeTrimmed() {
25+
Assertions.assertEquals("https://boolean.co.uk/who-we-are", this.exercise.url);
26+
}
27+
28+
@Test
29+
public void protocolShouldBeHttps() {
30+
Assertions.assertEquals("https", this.exercise.protocol);
31+
}
32+
33+
@Test
34+
public void domainShouldBeBooleanCoUk() {
35+
Assertions.assertEquals("boolean.co.uk", this.exercise.domain);
36+
}
37+
38+
@Test
39+
public void lengthShouldBe32() {
40+
Assertions.assertEquals(32, this.exercise.length);
41+
}
42+
43+
@Test
44+
public void faqUrlShouldBeBooleanCoUkFaq() {
45+
Assertions.assertEquals("https://boolean.co.uk/faq", this.exercise.faqUrl);
46+
}
47+
}

src/test/java/com/booleanuk/SampleTest.java

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)