From de038c012da529bb1b90df94d9a043b334d490f5 Mon Sep 17 00:00:00 2001 From: subhamBakshi Date: Wed, 12 Aug 2020 19:54:11 +0530 Subject: [PATCH] PROGRAD FSJ0620D111 --- .classpath | 6 +--- build/classes/.gitignore | 3 +- src/controller/PersonalityViewController.java | 11 ++++--- src/service/PersonalityCalculator.java | 32 +++++++++++++++++++ 4 files changed, 41 insertions(+), 11 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 611b17f..55bc0b6 100644 --- a/build/classes/.gitignore +++ b/build/classes/.gitignore @@ -1,3 +1,2 @@ -/service/ /controller/ -/testing/ +/service/ diff --git a/src/controller/PersonalityViewController.java b/src/controller/PersonalityViewController.java index bbf6331..6eee058 100644 --- a/src/controller/PersonalityViewController.java +++ b/src/controller/PersonalityViewController.java @@ -9,6 +9,8 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import service.PersonalityCalculator; + @WebServlet(urlPatterns= {"/personality"}) public class PersonalityViewController extends HttpServlet { @@ -33,8 +35,9 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response) String options=request.getParameter("selectedOptions"); System.out.println(options); - - /* + PersonalityCalculator pc = new PersonalityCalculator(); + String message = pc.findYourBrainType(options); + request.setAttribute("message", message); @@ -52,8 +55,8 @@ else if(message.equals("leftbrained")) { RequestDispatcher rd=this.getServletContext().getRequestDispatcher("/WEB-INF/views/neutralView.jsp"); rd.forward(request, response); } - - }*/ + + } } } diff --git a/src/service/PersonalityCalculator.java b/src/service/PersonalityCalculator.java index da9ce41..49f9e33 100644 --- a/src/service/PersonalityCalculator.java +++ b/src/service/PersonalityCalculator.java @@ -1,2 +1,34 @@ package service; +public class PersonalityCalculator{ + + public String findYourBrainType(String options){ + int array[] = findAnswers(options); + int a=array[0]+array[1]+array[2]+array[4]+array[7]+array[9]+array[10]+array[11]+array[13]+array[17]+array[19]; + int b=array[3]+array[5]+array[6]+array[12]+array[14]+array[15]+array[16]+array[18]; + int x=66-a+b; + System.out.println("Your total score "+x); + if((x>=22)&&(x<=55)) + return "Left-brained "; + if((x>=56)&&(x<=64)) + return "No clear preference "; + if((x>=65)&&(x<=100)) + return "Right-brained"; + return "false"; + } + + public int[] findAnswers(String options) { + String c[]=options.split(","); + int value=c.length; + int array[]=new int[value]; + int i=0; + for(String s:c) //for-each loop + { + array[i]=Integer.parseInt(s); + i++; + } + + return array; + } +} +