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
5 changes: 3 additions & 2 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
<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">
<attributes>
<attribute name="owner.project.facets" value="java"/>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<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/
/service/
Binary file not shown.
118 changes: 110 additions & 8 deletions src/service/FlamesCheckService.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,111 @@
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 java.util.*;
class flames
{
public static char findFlames(String name1, String name2)
{
name1 = name1.toLowerCase();
name2 = name2.toLowerCase();
String n1[] = name1.split(" ");
String n2[] = name2.split(" ");
name1="";
name2="";
int len1=n1.length;
int len2=n2.length;
for(int i=0;i<len1;i++)
{
name1 = name1+n1[i];
}
for(int i=0;i<len2;i++)
{
name2 = name2+n2[i];
}
int length = name1.length()+name2.length();
boolean check[] = new boolean[name2.length()];
for(int i=0;i<name2.length();i++)
{
check[i]=false;
}
for(int i=0;i<name1.length();i++)
{
for(int j=0;j<name2.length();j++)
{
if((check[j]==false) && (name1.charAt(i) == name2.charAt(j)))
{
check[j]=true;
length = length-2;
break;
}
}
}
boolean flames_check[] = new boolean[6];
for(int i=0;i<6;i++)
{
flames_check[i] = true;
}
int count = 6;
int k=1,deleted_letters=0;
int j;
for(j=0;j<=count;j++)
{
if(k <= length)
{
if(j == count)
{
j=0;
}
if(flames_check[j] == true)
{
k = k+1;
}
}
if((k-1)==length)
{
deleted_letters = deleted_letters+1;
flames_check[j] = false;
k = 1;
}
if(deleted_letters==6)
{
if(j==0)
{
return 'f';
}
else if(j==1)
{
return 'l';
}
else if(j==2)
{
return 'a';
}
else if(j==3)
{
return 'm';
}
else if(j==4)
{
return 'e';
}
else if(j==5)
{
return 's';
}
break;
}
}
return '\0';
}

public static void main(String args[])
{
String name1,name2;
Scanner sc = new Scanner(System.in);
name1 = sc.nextLine();
name2 = sc.nextLine();
name1 = name1.trim();
name2 = name2.trim();
char x=findFlames( name1, name2) ;
System.out.println(x);
}
}
54 changes: 27 additions & 27 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();
}
}
}