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
35 changes: 18 additions & 17 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?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">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="build/classes"/>
<classpathentry kind="output" path="src"/>
</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.
1 change: 1 addition & 0 deletions src/controller/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/FlamesCheck.class
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);
*
* }
*/

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

}
}

}
1 change: 1 addition & 0 deletions src/service/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/FlamesCheckService.class
47 changes: 46 additions & 1 deletion src/service/FlamesCheckService.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,54 @@
package service;

import java.util.*;
import java.lang.*;
import java.io.*;
// 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 string1,String string2) {
StringBuffer name1 = new StringBuffer(string1);
StringBuffer name2 = new StringBuffer(string2);

for(int i=0;i<name1.length();i++)
{
for(int j=0;j<name2.length();j++)
{
if(name1.charAt(i)==name2.charAt(j)){
name1.charAt(i);
name2.charAt(j);
i--;
j--;
break;

}
}
}
String flames_str = "flames";
int total_lenght=name1.length()+name2.length();
//System.out.println(string1+" "+string2);
while(flames_str.length()!=1)
{
int index = total_lenght%flames_str.length();
String temp;

if(index==0){
flames_str = flames_str.substring(0, flames_str.length()-1);
}
else{
flames_str = flames_str.substring(index,flames_str.length())+flames_str.substring(0, index-1);
}
}
System.out.println(flames_str);



return flames_str.charAt(0);

}

}
1 change: 1 addition & 0 deletions src/testing/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/TestFlamesCheckService.class
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();
}
}
}