Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
<attribute name="owner.project.facets" value="jst.web"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre1.8.0_241">
<attributes>
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="build/classes"/>
</classpath>
1 change: 0 additions & 1 deletion build/classes/.gitignore

This file was deleted.

Binary file modified build/classes/controller/FlamesCheck.class
Binary file not shown.
Binary file added build/classes/service/FlamesCheckService.class
Binary file not shown.
Binary file not shown.
58 changes: 29 additions & 29 deletions src/controller/FlamesCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import service.FlamesCheckService;

@WebServlet("/flames")
public class FlamesCheck extends HttpServlet {
Expand All @@ -34,34 +34,34 @@ 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);

}

}

}
42 changes: 42 additions & 0 deletions src/service/FlamesCheckService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,45 @@
// 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) {
name1 = name1.toLowerCase(); //making all characters to lowercase
name2 = name2.toLowerCase();
StringBuffer str1 = new StringBuffer(name1);
StringBuffer str2 = new StringBuffer(name2);
int len1 = str1.length();
int len2 = str2.length();
for(int i =0; i< len1; i++) {
char a = str1.charAt(i);
for(int j =0; j< len2; j++) {
char b = str2.charAt(j);
if(a == b) {
str1.deleteCharAt(i); //deletion of common chars
str2.deleteCharAt(j);
i = 0; //checking should start from first after the string length changes
j=0;
len1 = str1.length();
len2 = str2.length();
a = str1.charAt(0);
}
}
}
int len = len1+len2; //count of unique chars in 2 strings
int a = len -1; //as index is 1 less than the length
StringBuffer str3 = new StringBuffer("flames");
int len3 = str3.length();
for(int k =0; k<5; k++) { //5iteration. as 5 letters should be striked or removed
if(a >= len3) { //if unique count is more than the flames length
a = a % len3;
}
str3.deleteCharAt(a);
len3 = str3.length();
a = a+len-1;
//System.out.println("a"+a);
}
//System.out.println(str3);
char result = str3.charAt(0);
return result;

}
}
52 changes: 26 additions & 26 deletions src/testing/TestFlamesCheckService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}