From d018a9a296898679f267b6a906fb95df0a72034f Mon Sep 17 00:00:00 2001
From: NARNEHARIPRIYA <61201057+NARNEHARIPRIYA@users.noreply.github.com>
Date: Tue, 3 Mar 2020 10:03:29 +0530
Subject: [PATCH] modified
---
.classpath | 6 +--
build/classes/.gitignore | 2 +-
src/controller/PersonalityViewController.java | 16 ++++++--
src/service/PersonalityCalculator.java | 40 +++++++++++++++++++
src/testing/TestPersonalityCalculator.java | 4 +-
5 files changed, 56 insertions(+), 12 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..710eab3 100644
--- a/build/classes/.gitignore
+++ b/build/classes/.gitignore
@@ -1,3 +1,3 @@
/service/
-/controller/
/testing/
+/controller/
diff --git a/src/controller/PersonalityViewController.java b/src/controller/PersonalityViewController.java
index 08a7a13..730be85 100644
--- a/src/controller/PersonalityViewController.java
+++ b/src/controller/PersonalityViewController.java
@@ -1,13 +1,14 @@
package controller;
import java.io.IOException;
-
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import service.PersonalityCalculator;
+
// Do not edit or modify this class unless required.
@@ -37,14 +38,21 @@ 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);
+
// create an object for the PersonalityCalculator
// call the findYourBrainType method using the object created above and pass options as argument.
// The value returned from the method is of type string.
// Store the String returned in a string literal called as message
+
- /* Un the below lines to test your code l
-
+ /*un the below lines to test your code l*/
+
+
+
+
request.setAttribute("message", message);
if(message!=null)
@@ -62,7 +70,7 @@ else if(message.equals("leftbrained")) {
rd.forward(request, response);
}
- }*/
+ }
}
}
diff --git a/src/service/PersonalityCalculator.java b/src/service/PersonalityCalculator.java
index 7e837a0..eac1a7e 100644
--- a/src/service/PersonalityCalculator.java
+++ b/src/service/PersonalityCalculator.java
@@ -1,6 +1,46 @@
package service;
// Create a class called PersonalityCalculator
+ public class PersonalityCalculator
+{
+ public int[] findAnswers(String options)
+ {
+ int i=0;
+ String s[]=options.split(",");
+ int n=s.length;
+ int a[]=new int[n];
+ for (String b : s)
+ {
+ a[i]=Integer.parseInt(b);
+ i++;
+ }
+ return a;
+ }
+ public String findYourBrainType(String options)
+ {
+ int a[]=findAnswers(options);
+ int b=a[0]+a[1]+a[2]+a[4]+a[7]+a[9]+a[10]+a[11]+a[13]+a[17]+a[19];
+ int c= a[3]=a[3]+a[5]+a[6]+a[8]+a[12]+a[14]+a[15]+a[16]+a[18];
+ int x=66-b+c;
+ if((x>=20)&&(x<=55))
+ {
+ String str="Left-brained";
+ return str;
+ }
+ if((x>=56)&&(x<=64))
+ {
+ String str="No clear preference";
+ return str;
+ }
+ if((x>=65)&&(x<=100))
+ {
+ String str= "Right-brained";
+ return str;
+ }
+ return options;
+ }
+}
+
// PersonalityCalculator has two methods findAnswers and findYourBrainType
// int[] findAnswers(String options) and String findYourBrainType(String options) is the method prototype
// findAnswer() accepts String as an argument and returns integer array as an output
diff --git a/src/testing/TestPersonalityCalculator.java b/src/testing/TestPersonalityCalculator.java
index 653c596..127d7e1 100644
--- a/src/testing/TestPersonalityCalculator.java
+++ b/src/testing/TestPersonalityCalculator.java
@@ -1,5 +1,5 @@
package testing;
-/* Uncomment the below code to test your application
+/* Uncomment the below code to test your application*/
import static org.junit.Assert.assertEquals;
@@ -28,4 +28,4 @@ public void testFindYourBrainTypeMethod() {
e.printStackTrace();
}
}
-}*/
\ No newline at end of file
+}
\ No newline at end of file