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
30 changes: 13 additions & 17 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v9.0">
<attributes>
<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="output" path="build/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v9.0">
<attributes>
<attribute name="owner.project.facets" value="jst.web"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="build/classes"/>
</classpath>
2 changes: 1 addition & 1 deletion build/classes/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/controller/
/testing/
Binary file modified build/classes/controller/FlamesCheck.class
Binary file not shown.
Binary file added build/classes/service/FlamesCheckService.class
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,6 +13,8 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import service.FlamesCheckService;



@WebServlet("/flames")
Expand All @@ -33,35 +35,33 @@ 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);
*
* }
*/
String name2 = request.getParameter("crush");

FlamesCheckService fcs = new FlamesCheckService();
String name1 = request.getParameter("your");

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);

}

}

}
52 changes: 52 additions & 0 deletions src/service/FlamesCheckService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,55 @@
// 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) {
StringBuffer s1 = new StringBuffer(name1);
StringBuffer s2 = new StringBuffer(name2);
char c,d,e='\0';
for(int i=0;i<s1.length();i++) {
c=s1.charAt(i);
for(int j=0;j<s2.length();j++) {
d=s2.charAt(j);
if(c==d) {
s1.deleteCharAt(i);
s2.deleteCharAt(j);
i--;
j--;
break;
}
}
}
s1=s1.append(s2);
int k=6,l=0;
String s3="FLAMES";
while(k>1) {
for(int m=1;m<s1.length();m++) {
if(s3.charAt(l)!='X') {
l++;
if(l==6)
l=0;
}
else {
l++;
if(l==6)
l=0;
m--;
}
}
while(s3.charAt(l)=='X') {
l++;
if(l==6)
l=0;
}
s3=s3.substring(0,l)+"X"+s3.substring(l+1);
k--;
}

for(int i=0;i<s3.length();i++) {
if(s3.charAt(i)!='X')
e=s3.charAt(i);
}
return Character.toLowerCase(e);
}
}
55 changes: 28 additions & 27 deletions src/testing/TestFlamesCheckService.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
package testing;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;

import org.junit.Test;

import service.FlamesCheckService;

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();
}
}
}