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 added build/classes/controller/WebServelet.class
Binary file not shown.
Binary file added build/classes/service/FlamesCheckService.class
Binary file not shown.
Binary file not shown.
5 changes: 5 additions & 0 deletions src/controller/WebServelet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package controller;

public class WebServelet {

}
89 changes: 84 additions & 5 deletions src/service/FlamesCheckService.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,88 @@
package service;

// 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


import service.FlamesCheckService;

// Create a class called FlamesCheckService
public class FlamesCheckService {
public char findFlames(String name1, String name2) {
StringBuffer str1 = new StringBuffer(name1);
StringBuffer str2 = new StringBuffer(name2);
int len1 = str1.length();
int len2 = str2.length();
P: for (int i = 0; i < len1; i++)// label
{
char a = str1.charAt(i);

for (int j = 0; j < len2; j++) {
char b = str2.charAt(j);
if (a == b) {

str1.deleteCharAt(i);
str2.deleteCharAt(j);
len1 = str1.length();
len2 = str2.length();
i = 0;
j = 0;

}
}

}

int len = len1 + len2;
StringBuffer str3 = new StringBuffer("flames");
String str4 = new String();

P: for (int i = 0; i < 5; i++) {
int c = -1, d = 0, p = 0;

for (int j = 1; j <= len; j++) {
c++;
d++;

if (c > str3.length() - 1) {
char e = str3.charAt(p);
if (d == len) {
str3.deleteCharAt(p);

str4 = str3.substring(p, str3.length());

str3.delete(p, str3.length());

str3.insert(0, str4);

break;
} else {
p++;
if (p == str3.length()) {
p = 0;
}
}
} else {
char e = str3.charAt(c);
if (d == len) {
str3.deleteCharAt(c);

str4 = str3.substring(c, str3.length());

str3.delete(c, str3.length());

str3.insert(0, str4);

break;
}

}

}
}

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