diff --git a/.classpath b/.classpath
index 2846539..832187c 100644
--- a/.classpath
+++ b/.classpath
@@ -1,17 +1,16 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/build/classes/.gitignore b/build/classes/.gitignore
index 4e7e508..2558a2b 100644
--- a/build/classes/.gitignore
+++ b/build/classes/.gitignore
@@ -1 +1,2 @@
-/controller/
+/testing/
+/service/
diff --git a/build/classes/controller/FlamesCheck.class b/build/classes/controller/FlamesCheck.class
index fe7152f..31b3204 100644
Binary files a/build/classes/controller/FlamesCheck.class and b/build/classes/controller/FlamesCheck.class differ
diff --git a/src/controller/FlamesCheck.java b/src/controller/FlamesCheck.java
index b9b9a0b..bc8a549 100644
--- a/src/controller/FlamesCheck.java
+++ b/src/controller/FlamesCheck.java
@@ -13,6 +13,8 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import service.FlamesCheckService;
+
@WebServlet("/flames")
@@ -33,35 +35,35 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
- /*
- * Uncomment the below code to test your output
- * String name1 = request.getParameter("your");
- * String name2 = request.getParameter("crush");
- *
- * FlamesCheckService fcs = new FlamesCheckService();
- *
- * char k = fcs.findFlames(name1,name2);
- *
- * if (k == 'f') { RequestDispatcher rd=this.getServletContext().getRequestDispatcher("/WEB-INF/views/friends.jsp"
- * ); rd.forward(request, response);
- *
- * } else if (k == 'l') { RequestDispatcher rd=this.getServletContext().getRequestDispatcher("/WEB-INF/views/lovers.jsp")
- * ; rd.forward(request, response);
- *
- * } else if (k == 'a') { RequestDispatcher rd=this.getServletContext().getRequestDispatcher(
- * "/WEB-INF/views/affection.jsp"); rd.forward(request, response);
- *
- * } else if (k == 'm') { RequestDispatcher rd=this.getServletContext().getRequestDispatcher(
- * "/WEB-INF/views/marriage.jsp"); rd.forward(request, response);
- *
- * } else if (k == 'e') { RequestDispatcher rd=this.getServletContext().getRequestDispatcher("/WEB-INF/views/enemies.jsp"
- * ); rd.forward(request, response);
- *
- * } else if (k == 's') { RequestDispatcher rd=this.getServletContext().getRequestDispatcher(
- * "/WEB-INF/views/siblings.jsp"); rd.forward(request, response);
- *
- * }
- */
+
+ //Uncomment the below code to test your output
+ String name1 = request.getParameter("your");
+ String name2 = request.getParameter("crush");
+
+ FlamesCheckService fcs = new FlamesCheckService();
+
+ char k = fcs.findFlames(name1,name2);
+
+ if (k == 'f') { RequestDispatcher rd=this.getServletContext().getRequestDispatcher("/WEB-INF/views/friends.jsp"
+ ); rd.forward(request, response);
+
+ } else if (k == 'l') { RequestDispatcher rd=this.getServletContext().getRequestDispatcher("/WEB-INF/views/lovers.jsp")
+ ; rd.forward(request, response);
+
+ } else if (k == 'a') { RequestDispatcher rd=this.getServletContext().getRequestDispatcher(
+ "/WEB-INF/views/affection.jsp"); rd.forward(request, response);
+
+ } else if (k == 'm') { RequestDispatcher rd=this.getServletContext().getRequestDispatcher(
+ "/WEB-INF/views/marriage.jsp"); rd.forward(request, response);
+
+ } else if (k == 'e') { RequestDispatcher rd=this.getServletContext().getRequestDispatcher("/WEB-INF/views/enemies.jsp"
+ ); rd.forward(request, response);
+
+ } else if (k == 's') { RequestDispatcher rd=this.getServletContext().getRequestDispatcher(
+ "/WEB-INF/views/siblings.jsp"); rd.forward(request, response);
+
+ }
+
}
}
diff --git a/src/service/FlamesCheckService.java b/src/service/FlamesCheckService.java
index a8c006a..35de157 100644
--- a/src/service/FlamesCheckService.java
+++ b/src/service/FlamesCheckService.java
@@ -1,9 +1,49 @@
package service;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.*;
+import com.sun.xml.internal.bind.v2.schemagen.xmlschema.List;
+
// Create a class called FlamesCheckService
// FlamesCheckService has a method findFlames to find the flames between two names
// char findFlames(String name1, String name2) takes two strings as arguments
// Your task is to calculate the flames value and return the corresponding character as output
// You must return only the following values ['f','l','a','m','e','s']
// change the return value at the end of the method corresponding to your return value
-
+public class FlamesCheckService{
+ public char findFlames(String name1, String name2) {
+ System.out.println("Person 1 name"+name1);
+ String [] flames = {"f","l","a","m","e","s"};
+ ArrayList list2 = new ArrayList(Arrays.asList(flames));
+ int index=0;
+ String [] person1 = name1.split("");
+ for(int i=0;i list1 = new ArrayList(Arrays.asList(person1));
+ ArrayList list3 = new ArrayList(Arrays.asList(person2));
+ for(int i=0;i union = new ArrayList(list1);
+ union.addAll(list3);
+ int count = union.size()-1;
+ while(list2.size()>1) {
+ System.out.println("removing "+list2.get((index+count) % list2.size()));
+ index = (index+count) % list2.size();
+ list2.remove(index);
+ System.out.println("list = "+list2);
+ }
+ return list2.get(0).charAt(0);
+
+ }//end of method
+}//end of class
diff --git a/src/testing/TestFlamesCheckService.java b/src/testing/TestFlamesCheckService.java
index f3b45fe..22c64dc 100644
--- a/src/testing/TestFlamesCheckService.java
+++ b/src/testing/TestFlamesCheckService.java
@@ -8,30 +8,30 @@
public class TestFlamesCheckService {
FlamesCheckService fcs = new FlamesCheckService();
@Test
-// public void testFindFlamesMethod() {
-// String name1 = "Alex";
-// String name2 = "Joylin";
-// char temp = 'a';
-// assertEquals(temp,fcs.findFlames(name1, name2));
-// name1 = "Steffe";
-// name2 = "Bobby";
-// temp = 'm';
-// assertEquals(temp,fcs.findFlames(name1, name2));
-// name1 = "John";
-// name2 = "Jully";
-// temp = 'e';
-// assertEquals(temp,fcs.findFlames(name1, name2));
-// name1 = "George";
-// name2 = "Neythiri";
-// temp = 'l';
-// assertEquals(temp,fcs.findFlames(name1, name2));
-// try {
-// fcs.findFlames(null, null);
-// fcs.findFlames("AAA", null);
-// fcs.findFlames(null, "BBB");
-// }
-// catch(Exception e) {
-// e.printStackTrace();
-// }
-// }
+ public void testFindFlamesMethod() {
+ String name1 = "Alex";
+ String name2 = "Joylin";
+ char temp = 'a';
+ assertEquals(temp,fcs.findFlames(name1, name2));
+ name1 = "Steffe";
+ name2 = "Bobby";
+ temp = 'm';
+ assertEquals(temp,fcs.findFlames(name1, name2));
+ name1 = "John";
+ name2 = "Jully";
+ temp = 'e';
+ assertEquals(temp,fcs.findFlames(name1, name2));
+ name1 = "George";
+ name2 = "Neythiri";
+ temp = 'l';
+ assertEquals(temp,fcs.findFlames(name1, name2));
+ try {
+ fcs.findFlames(null, null);
+ fcs.findFlames("AAA", null);
+ fcs.findFlames(null, "BBB");
+ }
+ catch(Exception e) {
+ e.printStackTrace();
+ }
+ }
}