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
35 changes: 18 additions & 17 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v9.0">
<attributes>
<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="output" path="build/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v9.0">
<attributes>
<attribute name="owner.project.facets" value="jst.web"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="/home/swati/Downloads/servlet.jar"/>
<classpathentry kind="output" path="build/classes"/>
</classpath>
112 changes: 0 additions & 112 deletions README.md

This file was deleted.

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/
61 changes: 30 additions & 31 deletions src/controller/PersonalityViewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,51 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import service.PersonalityCalculator;

@WebServlet(urlPatterns= {"/personality"})
@WebServlet(urlPatterns = { "/personality" })
public class PersonalityViewController extends HttpServlet {
private static final long serialVersionUID = 1L;


public PersonalityViewController() {
super();

}
public PersonalityViewController() {
super();

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}

protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("Entering do get");
RequestDispatcher rd=this.getServletContext().getRequestDispatcher("/WEB-INF/views/personalityView.jsp");
RequestDispatcher rd = this.getServletContext().getRequestDispatcher("/WEB-INF/views/personalityView.jsp");
rd.forward(request, response);
}


protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


String options=request.getParameter("selectedOptions");

protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

String options = request.getParameter("selectedOptions");

System.out.println(options);

/*
PersonalityCalculator pc=new PersonalityCalculator();

// create an object for the PersonalityCalculator
String message= pc.findYourBrainType(options);

request.setAttribute("message", message);
if(message!=null)
{
if(message.equals("rightbrained")) {
RequestDispatcher rd=this.getServletContext().getRequestDispatcher("/WEB-INF/views/rightBrainView.jsp");

if (message != null) {
if (message.equals("rightbrained")) {
RequestDispatcher rd = this.getServletContext()
.getRequestDispatcher("/WEB-INF/views/rightBrainView.jsp");
rd.forward(request, response);
}
else if(message.equals("leftbrained")) {
RequestDispatcher rd=this.getServletContext().getRequestDispatcher("/WEB-INF/views/leftBrainView.jsp");
} else if (message.equals("leftbrained")) {
RequestDispatcher rd = this.getServletContext()
.getRequestDispatcher("/WEB-INF/views/leftBrainView.jsp");
rd.forward(request, response);
}
else {
RequestDispatcher rd=this.getServletContext().getRequestDispatcher("/WEB-INF/views/neutralView.jsp");
} else {
RequestDispatcher rd = this.getServletContext().getRequestDispatcher("/WEB-INF/views/neutralView.jsp");
rd.forward(request, response);
}

}*/

}
}


}
43 changes: 43 additions & 0 deletions src/service/PersonalityCalculator.java
Original file line number Diff line number Diff line change
@@ -1,2 +1,45 @@
package service;
import java.util.*;
public class PersonalityCalculator
{
// method
public int findAnswer(String options) {
// split the option and store in the separate string
String sc[] = options.split(",");
int n = sc.length;
int arr[] = new int[n];
for(int i=0; i<n ; i++) {
//parse int convert the string into the integer.
//change the type.
arr[i] = Integer.parseInt(sc[i]);
return arr[i];

}

int x=arr[0]+arr[1]+arr[2]+arr[4]+arr[7]+arr[9]+arr[10]+arr[11]+arr[13]+arr[17]+arr[19];
System.out.println(x);
int y=arr[3]+arr[5]+arr[6]+arr[12]+arr[14]+arr[15]+arr[16]+arr[18];
System.out.println(y);
int Z=66-x+y;
return Z;
}


public String findYourBrainType(String options) {

int Z=findAnswer(options);

if((Z>=20)&&(Z<=25)) {
return "Left-Brained";
}
else if((Z>=56)&&(Z<=64)) {
return "No clear preference ";
}
else if((Z>=65)&&(Z<=100)) {
return "Right-brained";
}
else
return "something went wrong";

}
}
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();
}
}
}*/
}