Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Java programming - question Tester Interface Class import java.util.ArrayList; import java.util.Scanner; public interface Tester { // This method takes a Scanner object contianint the input
Java programming - question
Tester Interface Class
import java.util.ArrayList; import java.util.Scanner; public interface Tester { // This method takes a Scanner object contianint the input // and returns an ArrayList object containing the output. // // Parameters: // Scanner input: is a Scanner object that is a stream of text // containing the input to your program. // // Returns: an ArrayList of Strings. Each string is a line of output // from your program. public ArrayList compute( Scanner log ); }
Junit Test Class
import static org.junit.jupiter.api.Assertions.*; import java.util.ArrayList; import java.util.Scanner; import org.junit.jupiter.api.Test; class FriendTest { private static String testInput0 = "end"; private static String [] testOutput0 = {}; private static String testInput1 = "Alice joins " + "Carol joins " + "Bob joins " + "Bob friends Alice " + "Bob friends Carol " + "Alice leaves " + "Bob leaves " + "Carol leaves " + "end"; private static String [] testOutput1 = { "Alice and Carol should be friends" }; private static String testInput2 = "Alice joins " + "Carol joins " + "Bob joins " + "Bob friends Alice " + "Bob friends Carol " + "Bob unfriends Carol " + "Bob friends Carol " + "Alice leaves " + "Bob leaves " + "Carol leaves " + "end"; private static String [] testOutput2 = { "Alice and Carol should be friends", "Alice and Carol should be friends" }; private static String testInput3 = "Alice joins " + "Carol joins " + "Bob joins " + "Bob friends Alice " + "Bob friends Carol " + "Dave joins " + "Dave friends Bob " + "Alice leaves " + "Bob leaves " + "Carol leaves " + "Dave leaves " + "end"; private static String [] testOutput3 = { "Alice and Carol should be friends", "Alice and Dave should be friends", "Carol and Dave should be friends" }; private static String testInput4 = "Alice joins " + "Carol joins " + "Bob joins " + "Bob friends Alice " + "Bob friends Carol " + "Dave joins " + "Dave friends Bob " + "Carol leaves " + "Carol joins " + "Carol friends Alice " + "Alice leaves " + "Bob leaves " + "Carol leaves " + "Dave leaves " + "end"; private static String [] testOutput4 = { "Alice and Carol should be friends", "Alice and Dave should be friends", "Carol and Dave should be friends", "Bob and Carol should be friends" }; private static String testInput5 = "Alice joins " + "Carol joins " + "Bob joins " + "Bob friends Alice " + "Bob friends Carol " + "Dave joins " + "Dave friends Bob " + "Eve joins " + "Eve friends Bob " + "Dave leaves " + "Dave joins " + "Dave friends Bob " + "Dave unfriends Bob " + "Dave friends Bob " + "Fred joins " + "Alice friends Fred " + "Bob friends Fred " + "Carol friends Fred " + "Bob leaves " + "Fred leaves " + "Alice friends Carol " + "Alice leaves " + "Carol leaves " + "Dave leaves " + "end"; private static String [] testOutput5 = { "Alice and Carol should be friends", "Alice and Dave should be friends", "Carol and Dave should be friends", "Alice and Eve should be friends", "Carol and Eve should be friends", "Dave and Eve should be friends", "Alice and Dave should be friends", "Carol and Dave should be friends", "Dave and Eve should be friends", "Alice and Dave should be friends", "Carol and Dave should be friends", "Dave and Eve should be friends", "Bob and Fred should be friends", "Carol and Fred should be friends", "Dave and Fred should be friends", "Eve and Fred should be friends", "Alice and Carol should be friends" }; private static Scanner mkTest( String input ) { return new Scanner( input ); } private static ArrayList mkOutput( String [] output ) { ArrayList al = new ArrayList(); for( String s : output ) { al.add( s ); } return al; } private static boolean doTest( String input, String [] output ) { Tester t = new Friend(); ArrayList al = t.compute( mkTest( input ) ); System.out.println( "Input: " ); System.out.println( input ); System.out.println( "Generated output" ); for( String s : al ) { System.out.println( s ); } System.out.println( "Expected output" ); for( String s : output ) { System.out.println( s ); } System.out.println( "---------------------------------------------------" ); return al != null && al.equals( mkOutput( output ) ); } @Test void testEmpty() { assertTrue( doTest( testInput0, testOutput0 ), "Empty test" ); } @Test void test1() { assertTrue( doTest( testInput1, testOutput1 ), "Basic recommendation" ); } @Test void test2() { assertTrue( doTest( testInput2, testOutput2 ), "Repeat recommendation" ); } @Test void test3() { assertTrue( doTest( testInput3, testOutput3 ), "Multiple recommendation" ); } @Test void test4() { assertTrue( doTest( testInput4, testOutput4 ), "Lots of users leave" ); } @Test void test5() { assertTrue( doTest( testInput5, testOutput5 ), "Lots of recommendations" ); } }Assignment 5 Instructor: Alex Brodsky Due: 12:00 noon, Monday, March 26, 2018 The purpose of this assignment is to get you to create and use maps and grag farther improve your programming skills As discussed in class and the first tutorial, for each problesa you will be provided with a description of the problem and a JUnit test clase to test your code A similar JUnit test other IDEs to run the JUnit clase will be used to evaluate your code You can use Eclipse or test class to test your code Your code must compile. If it does not comple, you will recelve a 0 on the assignment Figure l:-ww.stockphotosscrete.con/tree-photos/tree-vec Background: Social Networks Social networks are networks that repreesent relationships between people One common relationship is "friend". This relationship is bidirectional, e.g, if Alice is friends with Bob, then Bob is friends with Alice. Social networks are constantly changing as users join or leave the network, and friend or unfriend other users. Many social networks have a "friend recommender" feature that recommends new friends to members if they share a mutual friend. For example, if Alice is friends with Bob, and Carol befriends Bob, the system will recommend Alice and Carol to each other. Problem: Recommend Friends Given a series of user actions in the social network that is initially empty, recommend new possible friendships after one user friends another user. For example, if Alice, Bob, and Assignment 5 Instructor: Alex Brodsky Due: 12:00 noon, Monday, March 26, 2018 The purpose of this assignment is to get you to create and use maps and grag farther improve your programming skills As discussed in class and the first tutorial, for each problesa you will be provided with a description of the problem and a JUnit test clase to test your code A similar JUnit test other IDEs to run the JUnit clase will be used to evaluate your code You can use Eclipse or test class to test your code Your code must compile. If it does not comple, you will recelve a 0 on the assignment Figure l:-ww.stockphotosscrete.con/tree-photos/tree-vec Background: Social Networks Social networks are networks that repreesent relationships between people One common relationship is "friend". This relationship is bidirectional, e.g, if Alice is friends with Bob, then Bob is friends with Alice. Social networks are constantly changing as users join or leave the network, and friend or unfriend other users. Many social networks have a "friend recommender" feature that recommends new friends to members if they share a mutual friend. For example, if Alice is friends with Bob, and Carol befriends Bob, the system will recommend Alice and Carol to each other. Problem: Recommend Friends Given a series of user actions in the social network that is initially empty, recommend new possible friendships after one user friends another user. For example, if Alice, Bob, and
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started