@@ -7,35 +7,33 @@ 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 = "" ;
11-
10+ public String fixedUrl = brokenUrl .replace ("z" , "s" );
1211
1312 // Here's a documentation link for all string methods, use it to figure out how to complete the rest of these requirements:
1413 // https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/lang/String.html#method-summary
1514
1615
1716 // 2. There are currently some upper case characters in the URL. Using an appropriate string method on the fixedUrl member above,
1817 // set the value of lowerCasedUrl.
19- public String lowerCasedUrl = "" ;
18+ public String lowerCasedUrl = fixedUrl . toLowerCase () ;
2019
2120
2221 // 3. There is still white space on both ends of the URL! Use the appropriate string method to trim that white space
2322 // and set the value of the url member below
24- public String url = "" ;
23+ public String url = lowerCasedUrl . trim () ;
2524
2625
2726 // 4. Using the appropriate string method on url, set the value of the protocol member below
28- public String protocol = "" ;
27+ public String protocol = url . split ( ":" )[ 0 ] ;
2928
3029
3130 // 5. Using the appropriate string method on url, set the value of the domain member below
32- public String domain = "" ;
33-
31+ public String domain = url .split ("/" )[2 ];
3432
3533 // 6. Set the length member below to the length of the url member
36- public int length = 0 ;
34+ public int length = url . length () ;
3735
3836
3937 // 7. Using concatenation and existing members, set the faqUrl member below to the faq page of the boolean website
40- public String faqUrl = " " ;
38+ public String faqUrl = protocol + "://" + domain + "/faq " ;
4139}
0 commit comments