Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 24 Answers



A) Create a JSP page to accept a number from a user and display it in words:

Example: 123 – One Two Three. The output should be in red color.

Answer :

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Number to Words Converter</title>
<style>
    .red-text {
        color: red;
    }
</style>
</head>
<body>
    <h1>Number to Words Converter</h1>
    <form action="convert.jsp" method="post">
        <label for="number">Enter a number:</label>
        <input type="text" id="number" name="number" />
        <br /><br />
        <input type="submit" value="Convert to Words" />
    </form>

    <%-- Check if the number parameter is present in the request --%>
    <% if (request.getParameter("number") != null) { %>
        <%-- Convert the number to words --%>
        <%
            String number = request.getParameter("number");
            String[] words = {"Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"};
            String result = "";
            for (int i = 0; i < number.length(); i++) {
                int digit = Character.getNumericValue(number.charAt(i));
                result += words[digit] + " ";
            }
        %>
        <%-- Display the result in red color --%>
        <h2><span class="red-text"><%= result %></span></h2>
    <% } %>
</body>
</html>

Output :

 

B) Write a menu driven program in Java for the following: Assume Emp table with

attributes ( ENo, EName, salary, Desg ) is already created.

1. Insert

2. Update

3. Delete

4. Search

5. Display

6. Exit.

Answer :

import java.util.Scanner;

public class EmpTable {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int choice;
        do {
            System.out.println("\nEmp Table Menu:");
            System.out.println("1. Insert record");
            System.out.println("2. Update record");
            System.out.println("3. Delete record");
            System.out.println("4. Search by ENo");
            System.out.println("0. Exit");
            System.out.print("Enter your choice: ");
            choice = scanner.nextInt();
            switch (choice) {
                case 1:
                    insertRecord();
                    break;
                case 2:
                    updateRecord();
                    break;
                case 3:
                    deleteRecord();
                    break;
                case 4:
                    searchRecord();
                    break;
                case 0:
                    System.out.println("Exiting...");
                    break;
                default:
                    System.out.println("Invalid choice, please try again.");
            }
        } while (choice != 0);
        scanner.close();
    }

    private static void insertRecord() {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter ENo: ");
        int ENo = scanner.nextInt();
        System.out.print("Enter EName: ");
        String EName = scanner.next();
        System.out.print("Enter salary: ");
        double salary = scanner.nextDouble();
        System.out.print("Enter Desg: ");
        String Desg = scanner.next();
        // TODO: Add code to insert record into Emp table
        System.out.println("Record inserted successfully.");
    }

    private static void updateRecord() {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter ENo to update: ");
        int ENo = scanner.nextInt();
        // TODO: Check if record with ENo exists
        System.out.print("Enter new EName: ");
        String EName = scanner.next();
        System.out.print("Enter new salary: ");
        double salary = scanner.nextDouble();
        System.out.print("Enter new Desg: ");
        String Desg = scanner.next();
        // TODO: Add code to update record in Emp table
        System.out.println("Record updated successfully.");
    }

    private static void deleteRecord() {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter ENo to delete: ");
        int ENo = scanner.nextInt();
        // TODO: Check if record with ENo exists
        // TODO: Add code to delete record from Emp table
        System.out.println("Record deleted successfully.");
    }

    private static void searchRecord() {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter ENo to search: ");
        int ENo = scanner.nextInt();
        // TODO: Add code to search for record in Emp table based on ENo
        // TODO: Print the record if found, otherwise print "Record not found."
    }
}

Output :


Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 24 Answers Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 24 Answers Reviewed by technical_saurabh on December 15, 2022 Rating: 5

No comments:

Powered by Blogger.