From c4680cdf1e0a09936ecc56bd4dc5ab7e220b9194 Mon Sep 17 00:00:00 2001 From: Ravikachhadiya Date: Sun, 6 Sep 2020 13:03:34 +0530 Subject: [PATCH] FSJ0720A115 --- .classpath | 6 +- build/classes/.gitignore | 2 + build/classes/controller/FlamesCheck.class | Bin 1349 -> 2394 bytes src/controller/FlamesCheck.java | 58 +++++++------- src/service/FlamesCheckService.java | 84 +++++++++++++++++++++ src/testing/TestFlamesCheckService.java | 52 ++++++------- 6 files changed, 142 insertions(+), 60 deletions(-) diff --git a/.classpath b/.classpath index 2846539..20c137d 100644 --- a/.classpath +++ b/.classpath @@ -8,10 +8,6 @@ - - - - - + diff --git a/build/classes/.gitignore b/build/classes/.gitignore index 4e7e508..764c814 100644 --- a/build/classes/.gitignore +++ b/build/classes/.gitignore @@ -1 +1,3 @@ /controller/ +/testing/ +/service/ diff --git a/build/classes/controller/FlamesCheck.class b/build/classes/controller/FlamesCheck.class index fe7152f9157fd498f6faf543a7b8c5a0e811fa05..67b9ec41541a4e46ec3bbf1e20e9c28d1df151f0 100644 GIT binary patch delta 1115 zcmZWoO-~b16g{tbVLxePz5R#6c8;6h#w5)wG6aVoGCRDlbYxs zAl; z+SAV9GVbx1yvksX$8-`qa-yfLCz{&Bz?NuGJFB7@Ikq$^FHgvGNiJfVe%RW9*P}0| zRh_{e~GftCzj(W1b9PDUDEn47# zA3n4phycR4f+uK43>|n$7fC0-O8y;Ppfz+OPkx>JCf%SNTJaUV_(_NU7x_K%f6$K_ zO8*{JWcP6fF7k({l`60z3P6GhIXix191loUEv0x!NFXWS5yb>7Bxo0p@EBGqVkc4U z5J^}Gt(MVx8SRwOUKveN!Hcl|LjLU21X$1$RGeD6(Euff($}H9#9#B4udXOo{>S1K_94tiNP2s X&IGj06iD*{<;;NCJeq;An85-73)2y+ diff --git a/src/controller/FlamesCheck.java b/src/controller/FlamesCheck.java index b9b9a0b..e6022a1 100644 --- a/src/controller/FlamesCheck.java +++ b/src/controller/FlamesCheck.java @@ -5,6 +5,7 @@ 2. Uncomment the code inside the doPost method given in this class to run and see the output */ import java.io.IOException; +import service.*; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; @@ -33,35 +34,34 @@ 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); - * - * } - */ + + 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); + + } + } } diff --git a/src/service/FlamesCheckService.java b/src/service/FlamesCheckService.java index a8c006a..70456bb 100644 --- a/src/service/FlamesCheckService.java +++ b/src/service/FlamesCheckService.java @@ -7,3 +7,87 @@ // 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) { + int wordLength = cutChar(name1, name2); + //System.out.println("word length: " + wordLength); + + char[] flames = {'f','l','a','m','e','s'}; + int count = 0; + while(true) { + + for(int i =0; i= arr.length) { + return arr; + } + + char[] anotherArray = new char[arr.length - 1]; + + for (int i = 0, k = 0; i < arr.length; i++) { + + if (i == index) { + continue; + } + + anotherArray[k++] = arr[i]; + } + + return anotherArray; + } + + public static char[] convertCharArray(String str) + { + char[] ch = new char[str.length()]; + + for (int i = 0; i < str.length(); i++) { + ch[i] = str.charAt(i); + } + + return ch; + } +} diff --git a/src/testing/TestFlamesCheckService.java b/src/testing/TestFlamesCheckService.java index f3b45fe..22c64dc 100644 --- a/src/testing/TestFlamesCheckService.java +++ b/src/testing/TestFlamesCheckService.java @@ -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(); + } + } }