Question: Consider the following partial code: public class Item { private String url; private float price; public Item(String url) { this.url = url; } } Let's
Consider the following partial code:
public class Item {
private String url;
private float price;
public Item(String url) {
this.url = url;
}
}
Let's first rewrite the constructor of the item class to make it more robust by throwing a MalformedURLException when the given URL is not well-formed. Assume that:
- The java.net. MalformedURLException class is a subclass of the java.io.Exception class, which is a subclass of the java.lang.Exception.
- There is a helper method defined, boolean isWellFormedURL(String), that checks if a string is a well-formed URL.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
