0

Array contaning names

Create a function that takes an array contaning the names of people who likes the post of someone else blog. [] — nobody like this post ["Maria"] = Maria liked this post ["Maria, Sam, Troy"] = Maria, Sam Troy liked this post ["Maria, Sam, Troy, Josh Seb"] Maria, Sam and 3 others liked this post THE SAMPLE TEST CASE: import static org.junit.Assert.assertEquals; import org.junit.Test; public class LikedItSampleTest { @Test public void WorksForEmptyArray() { LikedIt likedIt = new LikedIt(); assertEquals(likedIt.likedIt(new String[0]), "Nobody likes this post"); } @Test public void WorksForArrayWithLengthThree() { LikedIt likedIt = new LikedIt(); assertEquals(likedIt.likedIt(new String[]{"Jerzeil Lira", "Danielle Kaye", "Marinel"}), "Jerzeil Lira, Danielle Kaye and Marinel like this post"); } @Test public void WorksForArrayWithLengthFour() { LikedIt likedIt = new LikedIt(); assertEquals(likedIt.likedIt(new String[]{"Mikko", "

16th Feb 2022, 11:16 PM
Romela Cathrille Mijares Zabala
Romela Cathrille Mijares Zabala - avatar
8 Antworten
+ 4
This is simple. Show your attempt first to get help
17th Feb 2022, 2:41 AM
Rishi
Rishi - avatar
+ 3
Your code runs fine for me. Next time when sharing your code, save it in the code playground and share it's link here https://code.sololearn.com/cUi7pSkRHe42/?ref=app
17th Feb 2022, 2:50 AM
Rishi
Rishi - avatar
+ 1
I still got 0/100 maybe I should follow the Sample Test Case how they label their codes. I can't do it on my own codes.
17th Feb 2022, 2:58 AM
Romela Cathrille Mijares Zabala
Romela Cathrille Mijares Zabala - avatar
+ 1
Romela Cathrille Mijares Zabala i suppose you've to get the input and print according to that
17th Feb 2022, 5:43 AM
Rishi
Rishi - avatar
0
This is my code import java.util.Arrays; public class Mod_12 { public static void empty(){ String [] name = { }; System.out.println (Arrays.toString(name) + " => Nobody likes this post"); } public static void onelikes(){ String[] name = {"Ikko"}; System.out.println (Arrays.toString(name) + " => " + name[0] + " likes this post"); } public static void threelikes(){ String[] name = {"Danielle", "Liza", "Sue"}; System.out.println (Arrays.toString(name) + " => " + name[0] + ", " + name[1] + " and " + name[2] + " likes this post"); } public static void fourlikes(){ String[] name = {"Ken", "James", "John", "Seb"}; System.out.println(Arrays.toString(name) + " =>" + name[0] + ", " + name[1] + " and 2 others like this post"); } public static void main(String x[]) { empty(); onelikes(); threelikes(); fourlikes(); } }
17th Feb 2022, 2:44 AM
Romela Cathrille Mijares Zabala
Romela Cathrille Mijares Zabala - avatar
0
It says it's wrong idk what's wrong but it runs. This is how it said: LikedItSampleTest.java:7: error: cannot find symbol LikedIt likedIt = new LikedIt(); ^ symbol: class LikedIt location: class LikedItSampleTest LikedItSampleTest.java:7: error: cannot find symbol LikedIt likedIt = new LikedIt(); ^ symbol: class LikedIt location: class LikedItSampleTest LikedItSampleTest.java:13: error: cannot find symbol LikedIt likedIt = new LikedIt(); ^ symbol: class LikedIt location: class LikedItSampleTest LikedItSampleTest.java:13: error: cannot find symbol LikedIt likedIt = new LikedIt(); ^ symbol: class LikedIt location: class LikedItSampleTest LikedItSampleTest.java:19: error: cannot find symbol LikedIt likedIt = new LikedIt(); ^ symbol: class LikedIt location: class LikedItSampleTest LikedItSampleTest.java:19: error: cannot find symbol LikedIt likedIt = new LikedIt(); ^ symbol: class LikedIt location: class LikedItSampleTest 6 errors Error: Could not find or load main class MainTest Caused by: java.lang.ClassNotFou
17th Feb 2022, 2:46 AM
Romela Cathrille Mijares Zabala
Romela Cathrille Mijares Zabala - avatar
0
I try the other one but still it's wrong import java.util.Arrays; public class Mod_12 { public static void main(String x[]) { String [] one = { }; String[] two = {"Ikko"}; String[] three = {"Danielle", "Liza", "Sue"}; String[] four = {"Ken", "James", "John", "Seb"}; System.out.println (Arrays.toString(one) + " => Nobody likes this post"); System.out.println (Arrays.toString(two) + " => " + two[0] + " likes this post"); System.out.println (Arrays.toString(three) + " => " + three[0] + ", " + three[1] + " and " + three[2] + " likes this post"); System.out.println(Arrays.toString(four) + " =>" + four[0] + ", " + four[1] + " and 2 others like this post"); }}
17th Feb 2022, 2:48 AM
Romela Cathrille Mijares Zabala
Romela Cathrille Mijares Zabala - avatar
0
There's no input in instructions. I don't know how to put this Assertion in java it's new to me. It's about Assertion and arrays with in each 3 public voids
17th Feb 2022, 9:36 AM
Romela Cathrille Mijares Zabala
Romela Cathrille Mijares Zabala - avatar