Write a function that provides change directory (cd) function for an abstract file system. Notes: Root path is '/'. Path separator is '/'. Parent directory is addressable as "..". Directory names consist only of English alphabet letters (A-Z and a-z). For example, new Path("/a/b/c/d").cd("../x").getPath() should return "/a/b/c/x". Note: The evaluation environment uses '\' as the path separator. public class Path { private String path; public Path(String path) { this.path = path; } public String getPath() { return path; } public Path cd(String newPath) { //throw new UnsupportedOperationException("Waiting to be implemented."); String[] newP=newPath.split("/"); String[] oldP=path.split("/"); int lnCount=0; for(String str:newP){ if(st...
Comments
Post a Comment