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>
2 changes: 1 addition & 1 deletion build/classes/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/service/
/controller/
/testing/
/controller/
16 changes: 12 additions & 4 deletions src/controller/PersonalityViewController.java
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -62,7 +70,7 @@ else if(message.equals("leftbrained")) {
rd.forward(request, response);
}

}*/
}
}
}

Expand Down
40 changes: 40 additions & 0 deletions src/service/PersonalityCalculator.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/testing/TestPersonalityCalculator.java
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -28,4 +28,4 @@ public void testFindYourBrainTypeMethod() {
e.printStackTrace();
}
}
}*/
}