编写一道图形记忆测试试题,掌握session bean存储用户的数据 步骤如下 (1)编写JavaBean类 Memory.java用于构建模型 (2)编写choiceGrage. jsp, 该页面中的form 表单中使用radio 标记选择记忆测试级别: 初级、中级和高级。初级需要记忆一个长度为5 个字符的字符序列(例如★■★▲●) , 中级需要记忆一个长度为7 个字符的字符序列,高级需耍记忆一个长度为10 个字符的字符序列。在choiceGrage.jsp 页面选择级别后,单击form 表单的提交键提交给giveTest. jsp 页面。 (3)编写giveTest. jsp 页面,该页面获取choiceGrage. jsp 贞面提交的级别后.使用session bean 显示testString 的屈性值(例如展性值是长度为7 个字符的字符序列),然后提示用户在5 秒内记住这个字符序列。5 秒后,该页面将自动定向到answerTest.jsp 页面。 (4)编写answerTest. jsp 页面, 该页面的form 表单提供用户给出答案的界面,即使用radio 标记让用户选择字符序列中的各个字符,以此代表用户认为自己记住的字符序列。单击提交键. 将选择提交给judgeAnswer. jsp 页面 (5)编写judgeAnswer. jsp 页面,该页面负责判断有户是否记住了giveTest. jsp 页面给出 的字符序列。
时间: 2023-06-20 18:07:13 浏览: 142
通过机器学习和图形用户界面预测在泰坦尼克号上的生存:该程序包含干净而优美的图形用户界面(GUI),可通过使用8种机器学习模型和数据可视化工具进行交互不同的Python库。 用户可以通过选择要在测试数据上运行的模型来与GUI交互,然后将其带到显示测试数据的预测结果以及一般模型准确性的屏幕。 该屏幕还包括各种按钮在被选择时,所述测试数据显示复杂的和有吸引力的数据可视化
5星 · 资源好评率100%
(1)编写JavaBean类 Memory.java用于构建模型
```java
import java.util.Random;
public class Memory {
private String testString;
public Memory() {
this.testString = "";
}
public String getTestString() {
return testString;
}
public void setTestString(int level) {
Random random = new Random();
if (level == 1) {
for (int i = 0; i < 5; i++) {
int r = random.nextInt(4);
switch (r) {
case 0:
testString += "★";
break;
case 1:
testString += "■";
break;
case 2:
testString += "★";
break;
case 3:
testString += "▲";
break;
case 4:
testString += "●";
break;
}
}
} else if (level == 2) {
for (int i = 0; i < 7; i++) {
int r = random.nextInt(4);
switch (r) {
case 0:
testString += "★";
break;
case 1:
testString += "■";
break;
case 2:
testString += "★";
break;
case 3:
testString += "▲";
break;
case 4:
testString += "●";
break;
}
}
} else if (level == 3) {
for (int i = 0; i < 10; i++) {
int r = random.nextInt(4);
switch (r) {
case 0:
testString += "★";
break;
case 1:
testString += "■";
break;
case 2:
testString += "★";
break;
case 3:
testString += "▲";
break;
case 4:
testString += "●";
break;
}
}
}
}
}
```
(2)编写choiceGrade.jsp页面
```html
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>选择记忆测试级别</title>
</head>
<body>
<h2>请选择记忆测试级别:</h2>
<form action="giveTest.jsp" method="post">
<label><input type="radio" name="level" value="1">初级</label><br>
<label><input type="radio" name="level" value="2">中级</label><br>
<label><input type="radio" name="level" value="3">高级</label><br>
<input type="submit" value="提交">
</form>
</body>
</html>
```
(3)编写giveTest.jsp页面
```html
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="javax.servlet.http.HttpSession"%>
<%@ page import="Memory"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>记忆测试</title>
</head>
<body>
<%
HttpSession session = request.getSession();
int level = Integer.parseInt(request.getParameter("level"));
Memory memory = new Memory();
memory.setTestString(level);
session.setAttribute("memory", memory);
%>
<h2>请在5秒内记住以下字符序列:</h2>
<h3><%= memory.getTestString() %></h3>
<%
response.setHeader("Refresh", "5;URL=answerTest.jsp");
%>
</body>
</html>
```
(4)编写answerTest.jsp页面
```html
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="javax.servlet.http.HttpSession"%>
<%@ page import="Memory"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>答题页面</title>
</head>
<body>
<%
HttpSession session = request.getSession();
Memory memory = (Memory) session.getAttribute("memory");
%>
<h2>请选择您记住的字符序列:</h2>
<form action="judgeAnswer.jsp" method="post">
<%
String testString = memory.getTestString();
for (int i = 0; i < testString.length(); i++) {
char c = testString.charAt(i);
%>
<label><input type="radio" name="answer" value="<%= c %>"><%= c %></label>
<% } %>
<br>
<input type="submit" value="提交">
</form>
</body>
</html>
```
(5)编写judgeAnswer.jsp页面
```html
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="javax.servlet.http.HttpSession"%>
<%@ page import="Memory"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>判断答案</title>
</head>
<body>
<%
HttpSession session = request.getSession();
Memory memory = (Memory) session.getAttribute("memory");
String testString = memory.getTestString();
String answer = request.getParameter("answer");
boolean isCorrect = true;
for (int i = 0; i < testString.length(); i++) {
if (testString.charAt(i) != answer.charAt(i)) {
isCorrect = false;
break;
}
}
%>
<h2>您的答案是:<%= answer %></h2>
<% if (isCorrect) { %>
<h3>恭喜您,答对了!</h3>
<% } else { %>
<h3>很遗憾,答错了!</h3>
<% } %>
</body>
</html>
```
阅读全文