Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CON-2878 Markdown Breakdown URL Exercise #2623

Merged
merged 3 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions subjects/java/checkpoints/breakdown-url/ExerciseRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import java.util.Map;

public class ExerciseRunner {
public static void main(String[] args) {
UrlParser parser = new UrlParser();

// Test case 1
String url1 = "https://www.example.com:8080/path?name=value";
Map<String, String> components1 = parser.parseURL(url1);
System.out.println("Components of URL 1: " + components1);

// Test case 2
String url2 = "http://example.com/";
Map<String, String> components2 = parser.parseURL(url2);
System.out.println("Components of URL 2: " + components2);

}
}
52 changes: 52 additions & 0 deletions subjects/java/checkpoints/breakdown-url/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
## URL Parsing

### Instructions

Create a class `UrlParser` that provides a method to parse and validate URLs using regex. The method should extract and return url components the `protocol`, `domain`, `port`, `path` and `query` parameters. The URL is always correct.

> give back in the map just the existing component.

### Expected Class

```java
public class UrlParser {
public Map<String, String> parseURL(String url) {
// Implementation to parse and validate URLs using regex
}
}
```

### Usage

Here is a possible `ExerciseRunner.java` to test your class:

```java
import java.util.Map;

public class ExerciseRunner {
public static void main(String[] args) {
UrlParser parser = new UrlParser();

// Test case 1
String url1 = "https://www.example.com:8080/path?name=value";
Map<String, String> components1 = parser.parseURL(url1);
System.out.println("Components of URL 1: " + components1);

// Test case 2
String url2 = "http://example.com/";
Map<String, String> components2 = parser.parseURL(url2);
System.out.println("Components of URL 2: " + components2);

}
}
```

### Expected Output

```shell
$ javac *.java -d build
$ java -cp build ExerciseRunner
Components of URL 1: {protocol=https, domain=www.example.com, port=8080, path=/path, query=name=value}
Components of URL 2: {protocol=http, domain=example.com, path=/}
$
```