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>
3 changes: 2 additions & 1 deletion build/classes/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/controller/
/service/
/testing/
Binary file modified build/classes/controller/FlamesCheck.class
Binary file not shown.
60 changes: 31 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,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);
*
* }
*/

//1\`aq1 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);

}

}

}
106 changes: 105 additions & 1 deletion src/service/FlamesCheckService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,108 @@
// 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) {

name1 = name1.trim().toLowerCase();
name2 = name2.trim().toLowerCase();

StringBuilder n1 =new StringBuilder(name1);
StringBuilder n2 = new StringBuilder(name2);

//char arr[] = {'f','l','a','m','e','s'};
int sn1 =n1.length();
int sn2 =n2.length();
int count = n1.length() + n2.length();
System.out.println(count);

for(int i=0; i<sn1; i++) {
for(int j=0; j<sn2;j++) {
if(n1.charAt(i) == n2.charAt(j)) {
count = count - 2;
n1.deleteCharAt(i);
n2.deleteCharAt(j);
sn1 = n1.length();
sn2 = n2.length();
i--;
j--;
break;
}
}
}

String f = "flames";
char ch;
int x=0;
StringBuffer flames = new StringBuffer(f);

//count holds a number of uncommon characters
/*
if(count > flames.length()) {
x = count % flames.length();
x=x-1;
ch =f.charAt(x);
}
else if(count == flames.length()) {
int c = count-1;
ch = f.charAt(c);
}
else {
ch =f.charAt(count-1);
}*/

if((count !=0) && (count !=flames.length())) {
if(count > flames.length()) {
x = (count-1) % flames.length();
//x=x-1;
ch =f.charAt(x);
}

else {
ch =f.charAt(count-1);
}
}
else if(count == (flames.length())) {

ch = f.charAt(5);
}

else {
ch =f.charAt(0);
}

System.out.println("count :"+count);
System.out.println("Your name is "+name1);
System.out.println("Your Partner name is "+name2);
System.out.println(ch);

switch(ch)
{
case 'f':
System.out.println("You Two are Friends");
break;


case 'l':
System.out.println("You Two are Love");
break;

case 'a':
System.out.println("You Two are Affection");
break;

case 'm':
System.out.println("You Two are Marriage");
break;

case 'e':
System.out.println("You Two are Enemy");
break;

case 's':
System.out.println("You Two are Siblings");
break;
}
return ch;
}
}
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();
}
}
}