Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
23 views

Java Lab Final

6th sem BCA java Programs

Uploaded by

Niki Gowthu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Java Lab Final

6th sem BCA java Programs

Uploaded by

Niki Gowthu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 77

DEPARTMENT OF COMPUTER

SCIENCE
GOVERNAMENT FIRST GRADE COLLEGE
KUSHALNAGAR, KODAGU-571234

CERTIFICATE
This is to certify that Mr./Mrs./Mis ………………………………………………………………………………………………………
Bearing Register………………………………………………………………………………………… has satisfactorily completed the

Course of experiments in practical Advanced JAVA and J2EE Lab BCACAPN605

Prescribed by Mangalore University 6th Sem BCA course in Laboratory of this college in
the year 2023-24
Particulars of the examination are given below:

Date of examination:

Time of examination:

Batch No. of Candidate:

Max marks for the paper:

(Sign of Lecturer in Charge) (Head of the Department)

Name:

Date:
For Official Use During Examination
This record has been valued at the University Practical Examination

1. Name of the External Examiner: Signature ………………………………………


1. Name of the Internal Examiner: Signature ……………………………………….
INDEX

PART - A
SL PROGRAM NAME P
NO. NO.

1 2-6

2 7-8

3 9-
15

4 16-
18
5 19-
23

6 24-
26

7 27-
29
PART – B
SL PROGRAM NAME P
NO NO
. .
1 30-
38

2 39-
47

3 03) Write a Java class called Simple Interest with methods for calculating 48-
simple interest. Have this class as a servant and create a server program and 51
register in the rmiregistry. Write a client program to invoke these remote
methods of the servant and do the calculations. Accept inputs at command
prompt.
4 52-
58
5 59-
65

6 66-
72
GFGC Kushalnagar

PART - A

Dept Of Computer Science 1


GFGC Kushalnagar

Num2Word.JAVA:
package num2word;
import java.u l.Scanner;

public class Num2Word {

public sta c void main(String[] args) {


Number num;
num = Number.EIGHTEEN;
Scanner in=new Scanner(System.in);
int n;
System.out.print("Enter a Number:");
n=in.nextInt();
System.out.println(num.convert(n));
}
}

Number.JAVA:
package num2word;
public enum Number {
ZERO(0),
ONE(1),
TWO(2),

Dept Of Computer Science 2


GFGC Kushalnagar

THREE(3),
FOUR(4),
FIVE(5),
SIX(6),
SEVEN(7),
EIGHT(8),
NINE(9),
TEN(10),
ELEVEN(11),
TWELVE(12),
THIRTEEN(13),
FOURTEEN(14),
FIFTEEN(15),
SIXTEEN(16),
SEVENTEEN(17),
EIGHTEEN(18),
NINETEEN(19),
TWENTY(20),
THIRTY(30),
FORTY(40),
FIFTY(50),
SIXTY(60),
SEVENTY(70),
EIGHTY(80),
NINETY(90),
HUNDRED(100),

Dept Of Computer Science 3


GFGC Kushalnagar

THOUSAND(1000);

private int number;


private Number(int num){
this.number=num;
}
public sta c String getWord(int n){
return Number.values()[n]+" ";
}
public String convert(int n){
if(n<0){
return "NEGATIVE" +convert(-n);
}
if(n==0){
return Number.getWord(n);
}
if(n>99999){
return "Error Out of Range!....";
}
String result="";
if(n>=20000){
result+=" "+Number.getWord(18+(n/1000))+" ";
n%=1000;
}
if(n>=1000){
result+=" "+Number.getWord(n/1000)+"Thousand";

Dept Of Computer Science 4


GFGC Kushalnagar

n%=1000;
}
if(n>=100){
result+=" "+Number.getWord(n/100)+"Hundred";
n%=100;
}
if(n>=20){
result+=" "+Number.getWord(18+(n/10))+" ";
n%=10;
}
if(n>0){
result+=" "+Number.getWord(n);
n%=1000;
}
return result;
}
}

Dept Of Computer Science 5


GFGC Kushalnagar

OUTPUT:
Enter a Number:1034
ONE Thousand THIRTY FOUR

Dept Of Computer Science 6


GFGC Kushalnagar

SecondMinMax.JAVA

package secondminmax;

import java.u l.Scanner;

import java.u l.Set;

import java.u l.TreeSet;

public class SecondMinMax {

public sta c void main(String[] args) {

Set<Integer>sortedset=new TreeSet<Integer>();

int n;

Scanner in=new Scanner(System.in);

System.out.print("Enter total number of elements in the set:");

n=in.nextInt();

if(n<2){

System.out.println("Please Enter at least two elements:");

}else{

System.out.println("Enter the values of"+n+"elements of the set");

for(int i=0;i<n;i++){

sortedset.add(in.nextInt());

Integer[] arr=sortedset.toArray(new Integer[0]);

System.out.println("Second maximum element:"+arr[arr.length-2]);

System.out.println("Second minimum element:"+arr[1]); }}}

Dept Of Computer Science 7


GFGC Kushalnagar

OUTPUT:
Enter total number of elements in the set:5

Enter the values of5elements of the set

4 5 32 3 43533

Second maximum element:32

Second minimum element:4

Dept Of Computer Science 8


GFGC Kushalnagar

ArrayLstDemo.JAVA

package arraylstdemo;

import java.u l.ArrayList;

import java.u l.Collec ons;

import java.u l.Scanner;

public class ArrayLstDemo {

public sta c void main(String[] args) {

int choice=7;

Scanner in=new Scanner(System.in);

ArrayList<Integer>alist=new ArrayList<Integer>();

int val,fval,pos;

do{

System.out.println(" MENU");

System.out.println("-----------------------");

System.out.println("1.Add");

System.out.println("2.Sort");

System.out.println("3.Replace");

System.out.println("4.Remove");

System.out.println("5.Display");

System.out.println("6.Add in between");

Dept Of Computer Science 9


GFGC Kushalnagar

System.out.println("7.Exit");

System.out.println("------------------------");

System.out.print("Enter Your Choice->");

choice=in.nextInt();

switch(choice){

case 1:

System.out.print("Enter a number:");

val=in.nextInt();

alist.add(val);

System.out.println("Item added to the list");

break;

case 2:

System.out.println("Sor ng...");

Collec ons.sort(alist);

System.out.println("Sor ng complete");

break;

case 3:

System.out.print("Enter value to find:");

fval=in.nextInt();

if(alist.contains(fval)){

System.out.print("Enter the replacement value:");

val=in.nextInt();

Collec ons.replaceAll(alist, fval, val);

System.out.println("Replacement completed");

Dept Of Computer Science 10


GFGC Kushalnagar

break;

}else{

System.out.println("Elements does not exist");

case 4:

System.out.print("Enter the element to remove");

val=in.nextInt();

if(alist.contains(val)){

alist.remove((Integer)val);

System.out.println("Element removed");

}else{

System.out.println("Element is not found");

break;

case 5:

System.out.println(alist);

break;

case 6:

System.out.print("Enter the index posi on:");

pos=in.nextInt();

if(pos<alist.size()){

System.out.print("Enter the value of new element:");

val=in.nextInt();

alist.add(pos,val);

Dept Of Computer Science 11


GFGC Kushalnagar

System.out.println("Element inserted");

}else{

System.out.println("Posi on out of bound");

break;

case 7:

System.out.println("Thank YOu");

return;

default:System.out.println("Wrong choice!\n Try Again");

break;

}while(true);

Dept Of Computer Science 12


GFGC Kushalnagar

OUTPUT:

MENU

-----------------------

1.Add

2.Sort

3.Replace

4.Remove

5.Display

6.Add in between

7.Exit

Enter Your Choice->1

Enter a number:10

Item added to the list

MENU

1.Add

2.Sort

3.Replace

4.Remove

5.Display

6.Add in between

7.Exit

Enter Your Choice->1

Enter a number:20

Dept Of Computer Science 13


GFGC Kushalnagar

Item added to the list

MENU

1.Add

2.Sort

3.Replace

4.Remove

5.Display

6.Add in between

7.Exit

Enter Your Choice->1

Enter a number:15

Item added to the list

MENU

1.Add

2.Sort

3.Replace

4.Remove

5.Display

6.Add in between

7.Exit

Enter Your Choice->2

Sor ng...

Sor ng complete

MENU

Dept Of Computer Science 14


GFGC Kushalnagar

1.Add

2.Sort

3.Replace

4.Remove

5.Display

6.Add in between

7.Exit

Enter Your Choice->5

[10, 15, 20]

MENU

1.Add

2.Sort

3.Replace

4.Remove

5.Display

6.Add in between

7.Exit

Enter Your Choice->7

Thank YOU

Dept Of Computer Science 15


GFGC Kushalnagar

WordManipula on.JAVA:

package wordmanipula on;

import java.u l.Scanner;

public class WordManipula on {

public sta c void main(String[] args) {

Scanner in=new Scanner(System.in);

String str;

System.out.println("Enter a string:");

str=in.nextLine();

int start=0;

String word="";

String togWord="";

str=str.trim()+" ";

String punct=" .,?!:;\n\t";

for(int i=0;i<str.length();i++){

if(punct.contains(str.charAt(i)+"")){

word=str.substring(start,i);

start=i+1;

word=word.trim();

if(word.length()>0 && word.length()%2==0){

Dept Of Computer Science 16


GFGC Kushalnagar

StringBuilder sb=new StringBuilder(word);

char tchar;

for(int j=1;j<word.length();j+=2){

tchar=sb.charAt(j);

sb.setCharAt(j, sb.charAt(j-1));

sb.setCharAt(j, tchar);

System.out.print(" "+sb);

StringBuilder tog=new StringBuilder(word);

for(int j=0;j<tog.length();j++){

if(Character.isUpperCase(tog.charAt(j))){

tog.setCharAt(j, Character.toLowerCase(tog.charAt(j)));

}else if(Character.isLowerCase(tog.charAt(j))){

tog.setCharAt(j, Character.toUpperCase(tog.charAt(j)));

togWord+=tog;

togWord+=str.charAt(i);

System.out.println("\n"+togWord);

Dept Of Computer Science 17


GFGC Kushalnagar

OUTPUT:

Enter a string:

Good Morning everyone

Good everyone

gOOD mORNING EVERYONE

Dept Of Computer Science 18


GFGC Kushalnagar

INDEX.HTML

<html>

<head>

< tle>Vo ng Eligibility Test</ tle>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, ini al-scale=1.0">

<style>

table{

background-color: aquamarine;

width: 200px;

margin-top: 100px;

margin-le : auto;

margin-right: auto;

border: solid 2px;

td{

padding: 5px;

Dept Of Computer Science 19


GFGC Kushalnagar

</style>

</head>

<body>

<form method="POST" ac on="CheckVoter">

<table>

<tr>

<td>Name</td>

<td><input type="text" name="uname"></td>

</tr>

<tr>

<td>Age</td>

<td><input type="text" name="age"></td>

</tr>

<tr>

<td></td>

<td><input type="submit" name="uname" value="check vo ng eligibility"></td>

</tr>

</table>

</form>

</body>

</html>

Dept Of Computer Science 20


GFGC Kushalnagar

CheckVoter.JAVA

package com;

import java.io.IOExcep on;

import java.io.PrintWriter;

import javax.servlet.ServletExcep on;

import javax.servlet.h p.H pServlet;

import javax.servlet.h p.H pServletRequest;

import javax.servlet.h p.H pServletResponse;

public class CheckVoter extends H pServlet {

protected void processRequest(H pServletRequest request, H pServletResponse response)

throws ServletExcep on, IOExcep on {

response.setContentType("text/html;charset=UTF-8");

try (PrintWriter out = response.getWriter()) {

out.println("<!DOCTYPE html>");

out.println("<html>");

out.println("<head>");

out.println("< tle>CheckVoter</ tle>");

out.println("</head>");

out.println("<body>");

String name=request.getParameter("uname");

int age=Integer.parseInt(request.getParameter("age"));

if(age>18){

out.println("<h4 style=\"color: brown\">"+name+ "Your are eligible to vote </h4>");

} else{

Dept Of Computer Science 21


GFGC Kushalnagar

out.println("<h4 style=\"color: brown\">"+name+ "Your are not eligible to vote


</h4>");

out.println("<a href=\"index.html\">Home</a>");

out.println("<h1>Servlet CheckVoter at " + request.getContextPath() + "</h1>");

out.println("</body>");

out.println("</html>");

@Override

protected void doGet(H pServletRequest request, H pServletResponse response)

throws ServletExcep on, IOExcep on {

processRequest(request, response);

@Override

protected void doPost(H pServletRequest request, H pServletResponse response)

throws ServletExcep on, IOExcep on {

processRequest(request, response);

@Override

public String getServletInfo() {

return "Short descrip on";

Dept Of Computer Science 22


GFGC Kushalnagar

OUTPUT:

Dept Of Computer Science 23


GFGC Kushalnagar

Fiboprime.JSP

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<html>

<head>

<meta h p-equiv="Content-Type" content="text/html; charset=UTF-8">

< tle>Fibonacci and Prime</ tle>

</head>

<body>

<h1>Fibonacci Series</h1>

<%

int a=0,b=1,c,i;

out.println(a+"&nbsp;&nbsp;"+b+"&nbsp;&nbsp;");

for(i=1;i<=10;i++){

c=a+b;

out.println(c+"&nbsp;&nbsp;");

a=b;

%>

<h1>Prime Number</h1>

<%

Dept Of Computer Science 24


GFGC Kushalnagar

int pn=2,count=1;

boolean isprime=true;

while(count<=10){

isprime=true;

for(i=2;i<=pn/2;i++){

if(pn%i==0){

isprime=false;

break;

if(isprime){

out.println(pn+"&nbsp;&nbsp;");

count++;

pn++;

%>

</body>

</html>

Dept Of Computer Science 25


GFGC Kushalnagar

OUTPUT:

Dept Of Computer Science 26


GFGC Kushalnagar

INDEX.HTML:

<!DOCTYPE html>

<html>

<head>

< tle>File Downloader</ tle>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, ini al-scale=1.0">

</head>

<body>

<a href="FileDownloader?filename=mycv.txt">Download My CV</a>

</body>

</html>

FileDownloader.JAVA

package com;

import java.io.IOExcep on;

import javax.servlet.ServletExcep on;

import javax.servlet.annota on.WebServlet;

import javax.servlet.h p.H pServlet;

import javax.servlet.h p.H pServletRequest;

import javax.servlet.h p.H pServletResponse;

import java.io.FileInputStream;

import java.io.OutputStream;

Dept Of Computer Science 27


GFGC Kushalnagar

public class FileDownloader extends H pServlet {

protected void processRequest(H pServletRequest request, H pServletResponse response)

throws ServletExcep on, IOExcep on {

String fname=request.getParameter("filename");

response.setContentType("text/plaintext");

response.setHeader("Content-Disposi on","a achment;filename=\""+fname+"\"");

OutputStream os= response.getOutputStream();

FileInputStream fis=new FileInputStream("C:\\bca\\mycv.txt");

int i=0;

while((i=fis.read())!=-1){

os.write(i);

fis.close();

os.close();

Dept Of Computer Science 28


GFGC Kushalnagar

OUTPUT:

PART - B

Dept Of Computer Science 29


GFGC Kushalnagar

]StudentInfoManagement.JAVA

package studen nfomanagement;

import java.sql.Connec on;

import java.u l.Scanner;

import java.sql.Date;

import java.sql.DriverManager;

import java.sql.SQLExcep on;

import java.sql.Statement;

import java.u l.logging.Level;

import java.u l.logging.Logger;

import org.apache.derby.client.am.ResultSet;

public class StudentInfoManagement {

Dept Of Computer Science 30


GFGC Kushalnagar

public sta c void main(String[] args) {

try {

Scanner in = new Scanner(System.in);

int choice = 5;

int regno;

String sname, sadd, sclass, scourse, dob, sql;

Class.forName("org.apache.derby.jdbc.ClientDriver");

Connec on con = DriverManager.getConnec on("jdbc:derby://localhost:1527/Student",


"Gowthu", "Gowthu@123");

Statement stmt = con.createStatement();

ResultSet rs;

do {

System.out.println("MENU");

System.out.println("****************************");

System.out.println("1.Add Student");

System.out.println("2.Delete Student");

System.out.println("3.Update Student");

System.out.println("4.Serach Student");

System.out.println("5.Exit");

System.out.println("*******************************");

System.out.print("Enter your Choice->");

choice = in.nextInt();

switch (choice) {

case 1:

System.out.println("Enter the Student Details");


Dept Of Computer Science 31
GFGC Kushalnagar

System.out.print("Reg No:");

regno = in.nextInt();

sname = in.nextLine();

System.out.print("Name:");

sname = in.nextLine();

System.out.print("DOB [yyyy-mm-dd]:");

dob = in.nextLine();

sname = in.nextLine();

System.out.print("Adress:");

sadd = in.nextLine();

System.out.print("Class:");

sclass = in.nextLine();

System.out.print("Course:");

scourse = in.nextLine();

sql = "INSERT INTO GOWTHU.STDTABLE (STREGNO, STNAME, STDOB, STADRESS,


STCLASS, STCOURSE)VALUES"

+ " (" + regno + ", '" + sname + "', '" + dob + "', '" + sadd + "', '" + sclass + "', '"
+ scourse + "')";

int result = stmt.executeUpdate(sql);

if (result == 1) {

System.out.println("Student details are saved...");

} else {

System.out.println("Error!!!...");

break;

Dept Of Computer Science 32


GFGC Kushalnagar

case 2:

System.out.print("Enter Student Reg No:");

regno = in.nextInt();

sql = "SELECT COUNT(*) FROM GOWTHU.STDTABLE WHERE STREGNO=" + regno;

rs = (ResultSet) stmt.executeQuery(sql);

rs.next();

if (rs.getInt(1) == 1) {

sql = "DELETE FROM GOWTHU.STDTABLE WHERE STREGNO=" + regno;

int res = stmt.executeUpdate(sql);

if (res == 1) {

System.out.println("Record deleted");

} else {

System.out.println("Error.....");

} else {

System.out.println("Record Not Found");

break;

case 3:

System.out.print("Enter the Register No:");

regno = in.nextInt();

in.nextLine();

sql = "SELECT COUNT(*) FROM GOWTHU.STDTABLE WHERE STREGNO=" + regno;

Dept Of Computer Science 33


GFGC Kushalnagar

rs = (ResultSet) stmt.executeQuery(sql);

rs.next();

if (rs.getInt(1) == 1) {

sql = "SELECT STADRESS FROM GOWTHU.STDTABLE WHERE STREGNO=" +


regno;

rs = (ResultSet) stmt.executeQuery(sql);

rs.next();

System.out.println("Old Adree is:" + rs.getString(1));

System.out.print("Enter the New Adress:");

String add = in.nextLine();

sql = "UPDATE GOWTHU.STDTABLE SET STADRESS='" + add + "' WHERE


STREGNO=" + regno;

if (stmt.executeUpdate(sql) == 1) {

System.out.println("Adress Updated");

} else {

System.out.println("Error...");

} else {

System.out.println("Student Record Not Found");

break;

case 4:

System.out.print("Enter the register no:");

regno = in.nextInt();

Dept Of Computer Science 34


GFGC Kushalnagar

sql = "SELECT * FROM GOWTHU.STDTABLE WHERE STREGNO=" + regno;

rs = (ResultSet) stmt.executeQuery(sql);

if (rs != null) {

rs.next();

System.out.println("Student Dteails are");

System.out.println("Reg No:" + rs.getInt(1));

System.out.println("Name:" + rs.getString(2));

System.out.println("Dob:" + rs.getString(3));

System.out.println("Adress:" + rs.getString(4));

System.out.println("Cladd:" + rs.getString(5));

System.out.println("Course:" + rs.getString(6));

break;

case 5:

stmt.close();

con.close();

System.out.println("Thank You");

return;

default:

System.out.println("Wrong Choice....\n Try Again....");

} while (true);

} catch (ClassNotFoundExcep on ex) {

Dept Of Computer Science 35


GFGC Kushalnagar

Logger.getLogger(StudentInfoManagement.class.getName()).log(Level.SEVERE, null, ex);

} catch (SQLExcep on ex) {

Logger.getLogger(StudentInfoManagement.class.getName()).log(Level.SEVERE, null, ex);

Dept Of Computer Science 36


GFGC Kushalnagar

OUTPUT:

MENU

****************************

1.Add Student

2.Delete Student

3.Update Student

4.Serach Student

5.Exit

*******************************

Enter your Choice->1

Enter the Student Details

Reg No:2001

Name:RAMA

DOB [yyyy-mm-dd]:2004-12-22

Adress:MADIKERI

Class:3BCA

Course:BCA

Student details are saved...

MENU

****************************

1.Add Student

2.Delete Student

3.Update Student

Dept Of Computer Science 37


GFGC Kushalnagar

4.Serach Student

5.Exit

*******************************

Enter your Choice->3

Enter the Register No:2001

Old Adree is:MADIKERI

Enter the New Adress:KUSHALNAGARA

Adress Updated

MENU

****************************

1.Add Student

2.Delete Student

3.Update Student

4.Serach Student

5.Exit

*******************************

Enter your Choice->5

Thank You

Dept Of Computer Science 38


GFGC Kushalnagar

BankMgt.JAVA

package bankmgt;import java.sql.*;

import java.u l.Scanner;

import java.sql.*;

public class BankMgt {

public sta c void main(String[] args) {

Connec on conn = null;

Scanner scanner = new Scanner(System.in); // Create a single Scanner object

try {

Class.forName("org.apache.derby.jdbc.ClientDriver");

conn = DriverManager.getConnec on("jdbc:derby://localhost:1527/BankDB", "vcp", "vcp");

int choice;

do {

Dept Of Computer Science 39


GFGC Kushalnagar

System.out.println("MENU");

System.out.println("1. Add new Account Holder informa on");

System.out.println("2. Amount Deposit");

System.out.println("3. Amount Withdrawal (Maintain minimum balance 500 Rs)");

System.out.println("4. Display all informa on");

System.out.println("5. Exit");

System.out.print("Enter your choice: ");

choice = scanner.nextInt();

switch (choice) {

case 1:

addNewAccountHolder(conn, scanner);

break;

case 2:

depositAmount(conn, scanner);

break;

case 3:

withdrawAmount(conn, scanner);

break;

case 4:

displayAllInforma on(conn);

break;

case 5:

System.out.println("Exi ng...");

break;

Dept Of Computer Science 40


GFGC Kushalnagar

default:

System.out.println("Invalid choice. Please try again.");

} while (choice != 5);

conn.close();

scanner.close();

} catch (SQLExcep on se) {

se.printStackTrace();

} catch (Excep on e) {

e.printStackTrace();

sta c void addNewAccountHolder(Connec on conn, Scanner scanner) {

try {

System.out.print("Enter Account Number: ");

int accNo = scanner.nextInt();

scanner.nextLine(); // Consume newline character

System.out.print("Enter Account Holder Name: ");

String accHolderName = scanner.nextLine();

System.out.print("Enter Address: ");

String address = scanner.nextLine();

System.out.print("Enter Ini al Balance: ");

double balance = scanner.nextDouble();

String sql = "INSERT INTO bank (accno, acname, address, balance) VALUES (?, ?, ?, ?)";

Dept Of Computer Science 41


GFGC Kushalnagar

PreparedStatement preparedStatement = conn.prepareStatement(sql);

preparedStatement.setInt(1, accNo);

preparedStatement.setString(2, accHolderName);

preparedStatement.setString(3, address);

preparedStatement.setDouble(4, balance);

int rowsInserted = preparedStatement.executeUpdate();

if (rowsInserted > 0) {

System.out.println("New account holder informa on added successfully!");

} else {

System.out.println("Failed to add new account holder informa on.");

} catch (SQLExcep on se) {

se.printStackTrace();

sta c void depositAmount(Connec on conn, Scanner scanner) {

try {

System.out.print("Enter Account Number: ");

int accNo = scanner.nextInt();

System.out.print("Enter Deposit Amount: ");

double amount = scanner.nextDouble();

String sql = "UPDATE bank SET balance = balance + ? WHERE accno = ?";

PreparedStatement preparedStatement = conn.prepareStatement(sql);

preparedStatement.setDouble(1, amount);

Dept Of Computer Science 42


GFGC Kushalnagar

preparedStatement.setInt(2, accNo);

int rowsUpdated = preparedStatement.executeUpdate();

if (rowsUpdated > 0) {

System.out.println("Amount deposited successfully!");

} else {

System.out.println("No account found with the given Account Number.");

} catch (SQLExcep on se) {

se.printStackTrace();

sta c void withdrawAmount(Connec on conn, Scanner scanner) {

try {

System.out.print("Enter Account Number: ");

int accNo = scanner.nextInt();

System.out.print("Enter Withdrawal Amount: ");

double amount = scanner.nextDouble();

String checkBalanceSql = "SELECT balance FROM bank WHERE accno = ?";

PreparedStatement checkBalanceStmt = conn.prepareStatement(checkBalanceSql);

checkBalanceStmt.setInt(1, accNo);

ResultSet resultSet = checkBalanceStmt.executeQuery();

if (resultSet.next()) {

double balance = resultSet.getDouble("balance");

if (balance - amount >= 500) {

Dept Of Computer Science 43


GFGC Kushalnagar

String updateSql = "UPDATE bank SET balance = balance - ? WHERE accno = ?";

PreparedStatement updateStmt = conn.prepareStatement(updateSql);

updateStmt.setDouble(1, amount);

updateStmt.setInt(2, accNo);

int rowsUpdated = updateStmt.executeUpdate();

if (rowsUpdated > 0) {

System.out.println("Amount withdrawn successfully!");

} else {

System.out.println("Failed to withdraw amount.");

} else {

System.out.println("Insufficient balance! Minimum balance of 500 Rs should be maintained.");

} else {

System.out.println("No account found with the given Account Number.");

} catch (SQLExcep on se) {

se.printStackTrace();

sta c void displayAllInforma on(Connec on conn) {

try {

Statement stmt = conn.createStatement();

String sql = "SELECT * FROM bank";

Dept Of Computer Science 44


GFGC Kushalnagar

ResultSet resultSet = stmt.executeQuery(sql);

while (resultSet.next()) {

System.out.println("Account Number: " + resultSet.getInt("accno"));

System.out.println("Account Name: " + resultSet.getString("acname"));

System.out.println("Address: " + resultSet.getString("address"));

System.out.println("Balance: " + resultSet.getDouble("balance"));

System.out.println("-----------------------------");

} catch (SQLExcep on se) {

se.printStackTrace();

Dept Of Computer Science 45


GFGC Kushalnagar

OUTPUT:

MENU

1. Add new Account Holder informa on

2. Amount Deposit

3. Amount Withdrawal (Maintain minimum balance 500 Rs)

4. Display all informa on

5. Exit

Enter your choice: 1

Enter Account Number: 2001

Enter Account Holder Name: RAMA

Enter Address: LAKKUR

Enter Ini al Balance: 500

New account holder informa on added successfully!

MENU

1. Add new Account Holder informa on

2. Amount Deposit

3. Amount Withdrawal (Maintain minimum balance 500 Rs)

4. Display all informa on

5. Exit

Enter your choice: 2

Enter Account Number: 2001

Enter Deposit Amount: 30000

Amount deposited successfully!

MENU

Dept Of Computer Science 46


GFGC Kushalnagar

1. Add new Account Holder informa on

2. Amount Deposit

3. Amount Withdrawal (Maintain minimum balance 500 Rs)

4. Display all informa on

5. Exit

Enter your choice: 4

Account Number: 123

Account Name: GOWTHAM

Address: KONANURU

Balance: 700.0

-----------------------------

Account Number: 2001

Account Name: RAMA

Address: LAKKUR

Balance: 30500.0

-----------------------------

MENU

1. Add new Account Holder informa on

2. Amount Deposit

3. Amount Withdrawal (Maintain minimum balance 500 Rs)

4. Display all informa on

5. Exit

Enter your choice: 5

Exi ng...

Dept Of Computer Science 47


GFGC Kushalnagar

03) Write a Java class called Simple Interest with methods for calcula ng simple interest. Have
this class as a servant and create a server program and register in the rmiregistry. Write a client
program to invoke these remote methods of the servant and do the calcula ons. Accept inputs
at command prompt.

ISimpleInterest.JAVA

package sirem;

import java.rmi.*;

public interface ISimpleInterest extends Remote {

double ComputeInterest(double p, double r, double t) throws RemoteExcep on;

SIClient.JAVA

package sirem;

import java.rmi.NotBoundExcep on;

import java.rmi.RemoteExcep on;

import java.rmi.registry.LocateRegistry;

import java.rmi.registry.Registry;

import java.u l.Scanner;

public class SIClient {

public sta c void main(String[] args) throws RemoteExcep on, NotBoundExcep on{

Registry reg=LocateRegistry.getRegistry(18888);

ISimpleInterest si=(ISimpleInterest) reg.lookup("SimpleInterest");

Scanner input =new Scanner(System.in);

double p,t,r;

String ans="n";

do{

Dept Of Computer Science 48


GFGC Kushalnagar

System.out.println("Simple Interest Calucula on");

System.out.print("Principle:");

p=input.nextDouble();

System.out.print("Time:");

t=input.nextDouble();

System.out.print("Rate: ");

r=input.nextDouble();

System.out.println("Simple Interest is : "+si.ComputeInterest(p,t,r));

input.nextLine();

ans=input.nextLine();

}while(ans.toLowerCase().charAt(0)=='Y');

SIRem.JAVA

package sirem;

public class SIRem {

public sta c void main(String[] args) {

SIServer.JAVA

package sirem;

import java.rmi.RemoteExcep on;

import java.rmi.server.UnicastRemoteObject;

Dept Of Computer Science 49


GFGC Kushalnagar

public class SIServer extends UnicastRemoteObject implements ISimpleInterest {

public SIServer() throws RemoteExcep on{

super();

@Override

public double ComputeInterest(double p, double r, double t) throws RemoteExcep on {

return (p*t*r)/100;

StartServer.JAVA

package sirem;

import java.rmi.AlreadyBoundExcep on;

import java.rmi.RemoteExcep on;

import java.rmi.registry.LocateRegistry;

import java.rmi.registry.Registry;

public class StartServer {

public sta c void main(String[] args) throws RemoteExcep on,AlreadyBoundExcep on{

SIServer si= new SIServer();

Registry reg = LocateRegistry.createRegistry(18888);

reg.bind("SimpleInterest", si);

System.out.println("Server Started....");

Dept Of Computer Science 50


GFGC Kushalnagar

OUTPUT:

Simple Interest Calucula on

Principle:10000

Time:3

Rate: 6

Simple Interest is : 1800.0

Dept Of Computer Science 51


GFGC Kushalnagar

4)

NewClass.JAVA

package com;

import java.io.Serializable;

public class NewClass implements Serializable{

private String regNo;

private String name;

private String course;

private String sem;

public NewClass(){

public String getRegNo() {

return regNo;

public void setRegNo(String regNo) {

this.regNo = regNo;

public String getName() {

return name;

public void setName(String name) {

Dept Of Computer Science 52


GFGC Kushalnagar

this.name = name;

public String getCourse() {

return course;

public void setCourse(String course) {

this.course = course;

public String getSem() {

return sem;

public void setSem(String sem) {

this.sem = sem;

INDEX.HTML

<html>

<head>

< tle>Student Info</ tle>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, ini al-scale=1.0">

</head>

<body>

<h2>Enter Student Details</h2>

Dept Of Computer Science 53


GFGC Kushalnagar

<form method="POST" ac on="firstPage.jsp">

<table>

<tr>

<td>Register No:</td>

<td><input type="text" name="regno"></td>

</tr>

<tr>

<td>Name:</td>

<td><input type="text" name="sname"></td>

</tr>

<tr>

<td>Course:</td>

<td><input type="text" name="course"></td>

</tr>

<tr>

<td>Semester:</td>

<td><input type="text" name="sem"></td>

</tr>

<tr>

<td> </td>

<td><input type="submit" name="subBtn" value="Register"></td>

</tr>

</table>

</form>

Dept Of Computer Science 54


GFGC Kushalnagar

</body>

</html>

FirstPage.JSP

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<meta h p-equiv="Content-Type" content="text/html; charset=UTF-8">

< tle>First JSP Page</ tle>

</head>

<body>

<h1>Student Details are Saved...</h1>

<jsp:useBean id="std" scope="session" class="com.NewClass">

<jsp:setProperty name="std" property="regNo" value="${param.regno}"/>

<jsp:setProperty name="std" property="name" value="${param.sname}"/>

<jsp:setProperty name="std" property="course" value="${param.course}"/>

<jsp:setProperty name="std" property="sem" value="${param.sem}"/>

</jsp:useBean>

<h2><a href="secondPage.jsp">View Student Details</a></h2>

</body>

</html>

SecondPage.JSP

Dept Of Computer Science 55


GFGC Kushalnagar

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@taglib prefix="c" uri="h p://java.sun.com/jsp/jstl/core" %>

<html>

<head>

<meta h p-equiv="Content-Type" content="text/html; charset=UTF-8">

< tle>Second JSP Page</ tle>

</head>

<body>

<h1>Student Details Are....</h1>

<table>

<tr>

<td>Register No:</td>

<td><c:out value="${std.regNo}"/></td>

</tr>

<tr>

<td>Name:</td>

<td><c:out value="${std.name}"/></td>

</tr>

<tr>

<td>Course:</td>

<td><c:out value="${std.course}"/></td>

</tr>

<tr>

<td>Semester:</td>

Dept Of Computer Science 56


GFGC Kushalnagar

<td><c:out value="${std.sem}"/></td>

</tr>

</table>

</body>

</html>

Dept Of Computer Science 57


GFGC Kushalnagar

OUTPUT:

Dept Of Computer Science 58


GFGC Kushalnagar

5)

MVCStudentResult.JAVA

package mvcstudentresult;

import java.u l.Scanner;

public class MVCStudentResult {

public sta c void main(String[] args) {

String rNo,sName;

int m1,m2,m3;

Scanner in=new Scanner(System.in);

System.out.print("Enter Roll No:");

rNo=in.nextLine();

System.out.print("Enter Name:");

sName=in.nextLine();

System.out.print("Marks in 3 Subjects:");

m1=in.nextInt();

m2=in.nextInt();

m3=in.nextInt();

Dept Of Computer Science 59


GFGC Kushalnagar

StudentModel sm=new StudentModel(rNo,sName,m1,m2,m3);

StudentView sv=new StudentView();

StudentController sc= new StudentController(sm,sv);

sc.UpdateView();

StudentController.JAVA

package mvcstudentresult;

public class StudentController {

private StudentModel model;

private StudentView view;

public StudentController(StudentModel model, StudentView view) {

this.model = model;

this.view = view;

public void UpdateView(){


view.DisplayResult(model.getRolno(),model.getName(),model.getM1(),model.getM2(),model.g
etM3(),model.getResult(),model.getGrade());

StudentModel.JAVA

package mvcstudentresult;

public class StudentModel {

private String rolno,name;

private int m1,m2,m3;

Dept Of Computer Science 60


GFGC Kushalnagar

public StudentModel(String rolno, String name, int m1, int m2, int m3) {

this.rolno = rolno;

this.name = name;

this.m1 = m1;

this.m2 = m2;

this.m3 = m3;

public String getRolno() {

return rolno;

public void setRolno(String rolno) {

this.rolno = rolno;

public String getName() {

return name;

public void setName(String name) {

this.name = name;

public int getM1() {

return m1;

public void setM1(int m1) {

this.m1 = m1;

Dept Of Computer Science 61


GFGC Kushalnagar

public int getM2() {

return m2;

public void setM2(int m2) {

this.m2 = m2;

public int getM3() {

return m3;

public void setM3(int m3) {

this.m3 = m3;

public String getResult(){

String result="";

if(m1<35 || m2<35 || m3<35){

result="Fail";

}else{

double per=((m1+m2+m3)/3);

if(per>=75){

result="Dis c on";

}else if(per>=65){

result="First Class";

}else if(per>=50){

Dept Of Computer Science 62


GFGC Kushalnagar

result="Second Class";

}else if(per>=35){

result="Third Class";

}else{

result="Fail";

return result;

public String getGrade(){

double per=((m1+m2+m3)/3);

String grade="";

if(per>=90){

grade="A";

}else if(per>=80){

grade="B";

}else if(per>=70){

grade="C";

}else if(per>=60){

grade="D";

}else{

grade="E";

return grade;

Dept Of Computer Science 63


GFGC Kushalnagar

StudentView.JAVA

package mvcstudentresult;

public class StudentView {

public void DisplayResult(String rNo,String sName,int m1,int m2,int m3,String result,String


grade){

System.out.println("***************************");

System.out.println("Roll No\tName\t\tMarks 1\tMarks 2\tMarks 3\tGrade");

System.out.println("****************************");

System.out.println(rNo+"\t"+sName+"\t"+m1+"\t"+m2+"\t"+m3+"\t"+result+"\t"+grade);

System.out.println("****************************");

Dept Of Computer Science 64


GFGC Kushalnagar

OUTPUT:

Enter Roll No:101

Enter Name:RAJU

Marks in 3 Subjects:

60

70

89

***************************

Roll No Name Marks 1 Marks 2 Marks 3 Grade

****************************

101 RAJU 60 70 89 First Class C

****************************

Dept Of Computer Science 65


GFGC Kushalnagar

06)

LinkedListMenu.JAVA

package linkedlistmenu;

import java.u l.LinkedList;

import java.u l.Scanner;

public class LinkedListMenu {

public sta c void main(String[] args) {

LinkedList<Integer> list = new LinkedList<>();

Scanner scanner = new Scanner(System.in);

int choice;

while (true) {

System.out.println("1. Insert at a specified posi on");

System.out.println("2. Swap two elements");

System.out.println("3. Iterate in reverse order");

System.out.println("4. Compare two linked lists");

System.out.println("5. Convert to array list");

System.out.println("6. Exit");

System.out.print("Enter your choice: ");

Dept Of Computer Science 66


GFGC Kushalnagar

choice = scanner.nextInt();

switch (choice) {

case 1:

System.out.print("Enter the element and posi on: ");

int element = scanner.nextInt();

int posi on = scanner.nextInt();

insertAtPosi on(list, element, posi on);

break;

case 2:

System.out.print("Enter the two elements to swap: ");

int element1 = scanner.nextInt();

int element2 = scanner.nextInt();

swapElements(list, element1, element2);

break;

case 3:

iterateReverse(list);

break;

case 4:

LinkedList<Integer> list2 = new LinkedList<>();

System.out.print("Enter the elements for the second list (enter -1 to stop): ");

int element3 = scanner.nextInt();

while (element3 != -1) {

list2.add(element3);

element3 = scanner.nextInt();

Dept Of Computer Science 67


GFGC Kushalnagar

if (compareLists(list, list2)) {

System.out.println("The two lists are equal");

} else {

System.out.println("The two lists are not equal");

break;

case 5:

int[] arrayList = convertToList(list);

System.out.print("Array list: ");

for (int i : arrayList) {

System.out.print(i + " ");

System.out.println();

break;

case 6:

System.exit(0);

public sta c void insertAtPosi on(LinkedList<Integer> list, int element, int posi on) {

list.add(posi on - 1, element);

public sta c void swapElements(LinkedList<Integer> list, int element1, int element2) {

Dept Of Computer Science 68


GFGC Kushalnagar

int index1 = list.indexOf(element1);

int index2 = list.indexOf(element2);

if (index1 != -1 && index2 != -1) {

list.set(index1, element2);

list.set(index2, element1);

public sta c void iterateReverse(LinkedList<Integer> list) {

for (int i = list.size() - 1; i >= 0; i--) {

System.out.print(list.get(i) + " ");

System.out.println();

public sta c boolean compareLists(LinkedList<Integer> list1, LinkedList<Integer> list2) {

if (list1.size()!= list2.size()) {

return false;

for (int i = 0; i < list1.size(); i++) {

if (list1.get(i)!= list2.get(i)) {

return false;

return true;

Dept Of Computer Science 69


GFGC Kushalnagar

public sta c int[] convertToList(LinkedList<Integer> list) {

int[] arrayList = new int[list.size()];

for (int i = 0; i < list.size(); i++) {

arrayList[i] = list.get(i);

return arrayList;

Dept Of Computer Science 70


GFGC Kushalnagar

OUTPUT:

1. Insert at a specified posi on

2. Swap two elements

3. Iterate in reverse order

4. Compare two linked lists

5. Convert to array list

6. Exit

Enter your choice: 1

Enter the element and posi on: 25 1

1. Insert at a specified posi on

2. Swap two elements

3. Iterate in reverse order

4. Compare two linked lists

5. Convert to array list

6. Exit

Enter your choice: 1

Enter the element and posi on: 50 2

1. Insert at a specified posi on

2. Swap two elements

3. Iterate in reverse order

4. Compare two linked lists

5. Convert to array list

6. Exit

Enter your choice: 1

Dept Of Computer Science 71


GFGC Kushalnagar

Enter the element and posi on: 75 3

1. Insert at a specified posi on

2. Swap two elements

3. Iterate in reverse order

4. Compare two linked lists

5. Convert to array list

6. Exit

Enter your choice: 3

75 50 25

1. Insert at a specified posi on

2. Swap two elements

3. Iterate in reverse order

4. Compare two linked lists

5. Convert to array list

6. Exit

Enter your choice: 6

Exi ng.....

Dept Of Computer Science 72

You might also like