package com.saket.demo.proxy; import java.util.ArrayList; import java.util.List; public…
- User
package com.saket.demo.proxy;
import java.util.ArrayList; import java.util.List;
public class ProxyInternet implements Internet { private Internet internet = new RealInternet(); private static List bannedSites;
static { bannedSites = new ArrayList<String>(); bannedSites.add("abc.com"); bannedSites.add("def.com"); bannedSites.add("ijk.com"); bannedSites.add("lnm.com"); } @Override public void connectTo(String serverhost) throws Exception { if(bannedSites.contains(serverhost.toLowerCase())) { throw new Exception("Access Denied"); } internet.connectTo(serverhost); }} which dependencies is needed for this code
- Assistant
There are no external dependencies required for this code. It only uses standard Java libraries.
- User
package com.saket.demo.proxy;
import java.util.ArrayList; import java.util.List;
public class ProxyInternet implements Internet { private Internet internet = new RealInternet(); private static List bannedSites;
static { bannedSites = new ArrayList<String>(); bannedSites.add("abc.com"); bannedSites.add("def.com"); bannedSites.add("ijk.com"); bannedSites.add("lnm.com"); } @Override public void connectTo(String serverhost) throws Exception { if(bannedSites.contains(serverhost.toLowerCase())) { throw new Exception("Access Denied"); } internet.connectTo(serverhost); }} remove error for this code
- Assistant
There are no syntax or logical errors in this code. However, the
Internetinterface it implements needs to be defined. Here's an example of what the interface could look like:public interface Internet { void connectTo(String serverHost) throws Exception; }Additionally, if the
RealInternetclass is used instead of being a placeholder, it needs to be defined as well. - User
package com.saket.demo.proxy;
import java.util.ArrayList; import java.util.List;
public class ProxyInternet implements Internet { private Internet internet = new RealInternet(); private static List bannedSites;
static { bannedSites = new ArrayList<String>(); bannedSites.add("abc.com"); bannedSites.add("def.com"); bannedSites.add("ijk.com"); bannedSites.add("lnm.com"); } @Override public void connectTo(String serverhost) throws Exception { if(bannedSites.contains(serverhost.toLowerCase())) { throw new Exception("Access Denied"); } internet.connectTo(serverhost); }} please correct this code for me which is runable in netbeans
- Assistant
If we assume that the
InternetandRealInternetinterfaces and classes have been defined, here's the corrected code that should work in NetBeans:package com.saket.demo.proxy; import java.util.ArrayList; import java.util.List; public class ProxyInternet implements Internet { private Internet internet = new RealInternet(); private static List<String> bannedSites; static { bannedSites = new ArrayList<String>(); bannedSites.add("abc.com"); bannedSites.add("def.com"); bannedSites.add("ijk.com"); bannedSites.add("lnm.com"); } @Override public void connectTo(String serverHost) throws Exception { if(bannedSites.contains(serverHost.toLowerCase())) { throw new Exception("Access Denied"); } internet.connectTo(serverHost); } }Make sure to save this file as
ProxyInternet.javain the correct package directory, and that theInternetandRealInternetinterfaces and classes are also saved in the correct package directories.