(PLEASE HELP ME)
Question:

Write an application that determines whether the first two files are located in the same folder as the third one. The program should prompt the user to provide 3 filepaths. If the files are in the same folder display All files are in the same folder, otherwise display Files are not in the same folder.


Test the program when the files are in the same folder and when they are not. The following filepaths can be used to test your program:


/root/sandbox/TestData1.txt

/root/sandbox/TestData2.txt

/root/sandbox/TestData3.txt and /root/sandbox/test/TestData3.txt

Grading

Write your Java code in the area on the right. Use the Run button to compile and run the code. Clicking the Run Checks button will run pre-configured tests against your code to calculate a grade.


Once you are happy with your results, click the Submit button to record your score.


MY CODE:

import java.nio.file.*;

import java.nio.file.attribute.*;

import java.io.IOException;

public class CompareFolders

{

public static void main(String[] args)

{

String path1 = "/root/sandbox/TestData1.txt";

String path2 = "/root/sandbox/TestData2.txt";

String path3 = "/root/sandbox/TestData3.txt";

System.out.println("Path1 :" +path1);

System.out.println("Path3 :" +path3);

compare(path1,path3);

System.out.println("Path2 :" +path2);

System.out.println("Path3 :" +path3);

compare(path2,path3);

}


private static void compare(String path_x, String path_y) {

if (path_x.startsWith(path_y)) {

System.out.println("All files are in the same folder");

}

else {

System.out.println("Files are not in the same folder");

}

}


}



ISSUE:

Test Case-Incomplete 66%

The program correctly indicates that files are in the same folder


What am I doing wrong?

Respuesta :

Answer:

/root/sandbox/TestData1.txt

/root/sandbox/TestData2.txt

/root/sandbox/TestData3.txt and /root/sandbox/test/TestData3.txt

Grading

Write your Java code in the area on the right. Use the Run button to compile and run the code. Clicking the Run Checks button will run pre-configured tests against your code to calculate a grade.

Once you are happy with your results, click the Submit button to record your score.

MY CODE:

import java.nio.file.*;

import java.nio.file.attribute.*;

import java.io.IOException;

public class CompareFolders

{

public static void main(String[] args)

{

String path1 = "/root/sandbox/TestData1.txt";

String path2 = "/root/sandbox/TestData2.txt";

String path3 = "/root/sandbox/TestData3.txt";

System.out.println("Path1 :" +path1);

System.out.println("Path3 :" +path3);

compare(path1,path3);

System.out.println("Path2 :" +path2);

System.out.println("Path3 :" +path3);

compare(path2,path3);

}

private static void compare(String path_x, String path_y) {

if (path_x.startsWith(path_y)) {

System.out.println("All files are in the same folder");

}

else {

System.out.println("Files are not in the same folder");