Q22

Question 22

Let the user enter a word in a textbox and let her/him select one of even or odd radio buttons. If she/he selects odd, check the odd positions in the word entered, if they all contain vowels, then display the message ‘You win’, else display ‘You lose’. Similarly, if the user selects even, check for vowels in all even positions in the word entered.

Created OddEvenGameServlet.java which handles GET requests of url pattern "/Q22" and "/game" also POST requests of url pattern "/q22/game/result" . For GET requests it renders oddeven.jsp page and asks user to input the string to play with and for POST requests it analyses the game logic with the servlet and then renders oddevenresult.jsp page with desired output.

Browse Source Code

Code

<%--
  Created by IntelliJ IDEA.
  User: HP
  Date: 24-04-2021
  Time: 21:04
  To change this template use File 
  | Settings 
  | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" 
language="java" %>
<html>
<head>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">

    <title>ODD-EVEN Game (Vowel Strings) | JSP-5</title>
</head>
<body>

<div style="text-align: center;">
    <div class="container-fluid">
        <h1> ODD-EVEN Game (Vowel Strings) | JSP-5</h1>
    </div>
</div>
<form method="post" action="/Q22/game/result">
    <div class="form-group">
        <div class="container-fluid mt-5 ">
            <div class="container mt-2">
                <label for="str">Enter the String
                </label>
            </div>
            <div class="container mt-2">
                <input type="textbox" 
                class="form-control w-75 p-3" 
                id="str" name="str" 
                placeholder="Type anything..." 
                required>
            </div>
            <div c
            lass="form-check container mt-2" 
            required>
                <div class="container mt-4">
                    <input class="form-check-input" 
                    type="radio" 
                    name="choice" 
                    id="odd" 
                    value="0">
                    <label class="form-check-label" 
                           for="odd">Odd</label><br>
                    <input class="form-check-input" 
                    type="radio" 
                    name="choice" 
                    id="even" 
                    value="1">
                    <label class="form-check-label" 
                    for="even">Even
                    </label>
                </div>
            </div>
            <div class="container mt-3 mx-10">
                <input type="submit" 
                formmethod="post" 
                class="btn btn-primary" 
                value="Check">
            </div>
        </div>

    </div>
</form>

<div class="card-footer mt-5 text-center">
    <div class="row align-items-start">
        <div class="col-6">
            <div class="container col-lg-6">
                <a class="btn btn-primary" 
                onclick="history.back(-1)" 
                role="button">Back</a>
            </div>

        </div>
        <div class="col-6">
            <div class="container col-lg-6">
                <a class="btn btn-primary" 
                href="http://localhost:8080/" 
                role="button">Home Page</a>
            </div>
        </div>
    </div>
</div>
</body>
</html>

Download oddeven.jsp

Output

Main Game Page (1/17)
A Loosing String(for both) Input for Odd Indexes (2/17)
Loosing String(for both) Output for Odd Indexes (3/17)
A Loosing String(for both) Input for Even Indexes (4/17)
Loosing String(for both) Output for Even Indexes (5/17)
Winning Input(for both) For Odd Indexes (6/17)
Winning String(for both) Output for Odd Indexes (7/17)
Winning Input(for both) for Even Indexes (8/17)
Winning String(for both) Output for Even Indexes (9/17)
Input of Odd Losing and Even Winning String (10/17)
Output for Only Odd Losing String (11/17)
Input of Only Odd Losing and Even Winning String (12/17)
Output for Only Even Winning String (13/17)
Input of Only Even Losing and Odd Winning String (14/17)
Output for Only Odd Winning (15/17)
Input of Only Even Losing and Odd Winning String (16/17)
Output for Only Even Loosing String (17/17)
Run Code Here

Last updated