Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Project 1 involves building a Web application that is designed using Java Server

ID: 3685058 • Letter: P

Question

Project 1 involves building a Web application that is designed using Java Server Pages (JSP) Model-View-Controller (MVC) Design Pattern and Model 1 Architecture (Covers Module 2: Java Server Pages) This project is intended to enforce your knowledge in: Developing Web Applications using Model 1 Web-application implementation using a View-Controller JSP page and a Model JavaBean. Project Requirements Develop and implement the “Subtraction Quiz” Web application using Model 1 architecture, that: Write a JSP program that generates subtraction quizzes randomly, as shown in Figure 1a.The first number must always be greater than or equal to the second number. After the user answers all questions, the JSP displays the result, as shown in Figure 1b.

Explanation / Answer

<%
int NUMBER_OF_QUESTIONS = 5; //number of questions
int correctCount = 0; //count the number of correct answers
int count = 0; // count the number of questions
String output = ""; //output string is initially empty

  
while (count < NUMBER_OF_QUESTIONS) {
//1.GENERATE TWO RANDOM SINGLE-DIGITS INTEGERS
int number1 = (int)(Math.random() * 10);
int number2 = (int)(Math.random() * 10);

//2.if number1 < number2, swap number1 with number2
if (number1 < number2) {
int temp = number1;
number1 = number2;
number2 = temp;
}
//prompt the student to answer"what is number1-number2"
out.println("What is " + number1 + "-" + number2 + "? ");
String inputString = request.getParameter("in");
//convert string to integer
input = Integer.parseInt(inputString);
answer = number1 - number2;
//4. grade the answer and display the result
if (input == answer){
out.println( "You are correct");
correctCount++;
}
else
out.println("Your answer is wrong. " + number1 + "-" + number2 + " should be " + answer);

//increase the count
count++;
}
%>