Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7935907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:03:42+00:00 2026-06-03T22:03:42+00:00

I’m working on a java quiz application. The application will consist of 20 questions

  • 0

I’m working on a java quiz application. The application will consist of 20 questions of one of the following forms:

What is the english word for the german word xxxx?

What is the german
word of the english word xxxx?

I have created a database with a word table and a page to add words to that table.
the table consists of the following columns: germanWord, gender, englishWord

My problem is that upon each question, I would like to randomly pick a word from that database to form the question so for example:

What is the german word of the english word wordTable.getEnglishName?

Lastly, the question is a multiple choice question so is it possible that in one of the 4 possible answers I could insert a command to take the relevant answer from that same entry that is chosen for the question?

<input type="radio" name="q1Answer" value="A"/><label for="A">A) fixed answer</label><br/>
<input type="radio" name="q1Answer" value="B"/><label for="B">B) fixed answer</label><br/>
<input type="radio" name="q1Answer" value="C"/><label for="C">C) *get name from the database*</label><br/>
<input type="radio" name="q1Answer" value="D"/><label for="D">D) fixed answer</label><br/><br/>



package org.me.jsp.beans;

import java.sql.*;
import java.util.*;

public class WordDataBean {


    private Connection connection;
    private PreparedStatement addWord, getWords, removeWord, getRandEnglishWord;

    public WordDataBean() throws Exception {

        try {
            Class.forName("com.mysql.jdbc.Driver");
            connection = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/university2", "root",
                    "");

            getWords = connection.prepareStatement("SELECT * FROM word");

            addWord = connection.prepareStatement("INSERT INTO university2.word ( "
                    + "germanName, gender, englishName ) " + "VALUES ( ?, ?, ?);");
            
            removeWord = connection.prepareStatement("DELETE FROM university2.student "
                    + "WHERE germanName='?';");
            getRandEnglishWord= connection.prepareStatement("SELECT englishName FROM word"
                    + "ORDER BY RAND() LIMIT 1");
        } catch (SQLException sqle) {
            sqle.printStackTrace();
        }

    }

    public List<WordBean> getWordList() throws SQLException {
        List<WordBean> wordList = new ArrayList<WordBean>();

        // obtain list of titles
        ResultSet results = getWords.executeQuery();

        // get row data
        while (results.next()) {
            WordBean word = new WordBean();

            word.setGermanName(results.getString(1));
            word.setGender(results.getString(2));
            word.setEnglishName(results.getString(3));

            wordList.add(word);
        }

        return wordList;
    }

    public void addWord(WordBean word) throws SQLException {
        addWord.setString(1, word.getGermanName());
        addWord.setString(2, word.getGender());
        addWord.setString(3, word.getEnglishName());
        addWord.executeUpdate();
    }
    
    public void removeWord(WordBean word) throws SQLException{
        removeWord.setString(1,word.getGermanName());
        removeWord.executeUpdate();
    }
    public void randomEnglishWord(WordBean word) throws SQLException{
        getRandEnglishWord.setString(1, word.getEnglishName());
        getRandEnglishWord.executeQuery();
    }
    protected void finalize() {
        try {
            getWords.close();
            addWord.close();
            connection.close();
        } catch (SQLException sqlException) {
            sqlException.printStackTrace();
        }
    }
}

Here is a sample of one of the question jsp pages, q1.jsp:

<%-- 
    Document   : q1
    Created on : 06-May-2012, 18:54:24
    Author     : encore
--%>

<!--This JSP acts as the first question in a multiple choice quiz, with the user
asked to submit their answer to the question-->

<?xml version = "1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>Big Java Quiz, question 1</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <%if(request.getParameter("choice").equals("N"))
            out.print("<meta http-equiv='refresh' content='0;url=options.jsp'/>");
            //Redirects user back to index if they did not want to take quiz%>
        <form action="q2.jsp" method="POST">
            <b>Question 1.</b> What is the German noun for the English word ______?<br/><br/>
            <input type="radio" name="q1Answer" value="A"/><label for="A">A) Exception generator</label><br/>
            <input type="radio" name="q1Answer" value="B"/><label for="B">B) Exception manipulator</label><br/>
            <input type="radio" name="q1Answer" value="C"/><label for="C">C) Exception handler</label><br/>
            <input type="radio" name="q1Answer" value="D"/><label for="D">D) Exception monitor</label><br/><br/>
            <input type="submit" value="Submit"/>
        </form>
    </body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T22:03:43+00:00Added an answer on June 3, 2026 at 10:03 pm

    Assuming you fetch your questions to a list:

        List<WordBean> wordList = getWordList();
        List<String> answersList = new ArrayList<String>(); 
        Random random = new Random();
        Random forAnswers = new Random();
    
        WordBean goodOne = wordList.get(random.nextInt(wordList.size()));
        //take it out from the list
        wordList.remove(goodOne);
        //add it to the answers list
        answersList.add(goodOne.getGermanName());
        WordBean fakeOne = wordList.get(random.nextInt(wordList.size()));
        //take it out from the list
        wordList.remove(fakeOne);
        //add it to the answers list
        answersList.add(fakeOne.getGermanName());
        WordBean fakeTwo = wordList.get(random.nextInt(wordList.size()));
        //take it out from the list
        wordList.remove(fakeTwo);
        //add it to the answers list
        answersList.add(fakeTwo.getGermanName());
    
        %>What is the english word for the german word <%=goodOne.getGermanName()%>
    
        <%
        char letter = 'A';
        for (String answer:answersList){
        %>
        <input type="radio" name="q1Answer" value=""/><label for="<%=letter%>"><%=letter%>)<%=answerList.get(forAnswers.getNextInt(3))> />
        <%
        //point to the next letter
        letter++;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to
I am writing an app with both english and french support. The app requests
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.