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
10 changes: 8 additions & 2 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@
<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">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="C:/Users/Dell/.m2/repository/org/apache/tomcat/tomcat-servlet-api/9.0.35/tomcat-servlet-api-9.0.35.jar" sourcepath="C:/Users/Dell/.m2/repository/org/apache/tomcat/tomcat-servlet-api/9.0.35/tomcat-servlet-api-9.0.35-sources.jar">
<attributes>
<attribute name="owner.project.facets" value="java"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.archivename" value="tomcat-servlet-api-9.0.35.jar"/>
<attribute name="maven.groupId" value="org.apache.tomcat"/>
<attribute name="maven.artifactId" value="tomcat-servlet-api"/>
<attribute name="maven.version" value="9.0.35"/>
<attribute name="maven.scope" value="compile"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="build/classes"/>
Expand Down
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.
62 changes: 31 additions & 31 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 @@ -25,43 +27,41 @@ public FlamesCheck() {
}

protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
throws ServletException, IOException {
RequestDispatcher rd = this.getServletContext().getRequestDispatcher("/WEB-INF/views/check.jsp");
rd.forward(request, 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 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);

}

}

}
29 changes: 29 additions & 0 deletions src/service/FlamesCheckService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,32 @@
// 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) {
String temp="";
int comcount=0;
for(int i=0;i<name1.length();i++) {
for(int j=0;j<name2.length();j++) {
if(name1.charAt(i)==(name2.charAt(j))) {
comcount+=2;
}
}
}
int count=name1.length()+name2.length()-comcount;
String flamescheck="flames";
while(flamescheck.length()!=1) {
int templen=count%flamescheck.length();
if(templen!=0) {
temp = flamescheck.substring(templen)+flamescheck.substring(0, templen-1);
}
else {
temp = flamescheck.substring(0, flamescheck.length()-1);
}
flamescheck = temp;
}
char res = flamescheck.charAt(0);
return res;
}

}

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