Ilovepdf Merged
Ilovepdf Merged
Experiment- 1.1
Given the following table containing information about employees of an organization, develop
a small java application, which accepts employee id from the command prompt and displays
the details.
Program Code :
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println();
System.out.print("Enter Employee ID: ");
int empId = sc.nextInt();
String[][] empDetails = {
{"1001", "Ashish", "01/04/2009", "e", "R&D", "20000", "8000", "3000"},
{"1002", "Sushma", "23/08/2012", "c", "PM", "30000", "12000", "9000"},
{"1003", "Rahul", "12/11/2008", "k", "Acct", "10000", "8000", "1000"},
{"1004", "Chahat", "29/01/2013", "r", "Front Desk", "12000", "6000", "2000"},
{"1005", "Ranjan", "16/07/2005", "m", "Engg", "50000", "20000", "20000"},
{"1006", "Suman", "1/1/2000", "e", "Manufacturing", "23000", "9000", "4400"},
{"1007", "Tanmay", "12/06/2006", "c", "PM", "29000", "12000", "10000"}
};
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
if (!found) {
System.out.println("There is no employee with empid: " + empId);
}
}
switch (index) {
case 0:
return daAmounts[0];
case 1:
return daAmounts[1];
case 2:
return daAmounts[2];
case 3:
return daAmounts[3];
case 4:
return daAmounts[4];
default:
return 0;
}
}
}
Output :
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
4. Learning Outcomes :
3. Learnt about basics of java and concepts of object oriented programming and its
implementation in java.
Experiment- 2.1
1. Aim : Create a program to collect and store all the cards to assist the users in finding all the
cards in a given symbol using Collection interface.
2. Objective : Develop a program that utilizes the Collection interface to efficiently collect
and store all cards, enabling users to easily find and retrieve all cards associated with a given
symbol.
3. Procedure : To create a program that collects and stores all the cards to assist users in
finding all the cards in a given symbol using a Collection interface, you can follow these
steps :
1. De ne the Card class: Create a class to represent a single card. Each card should have attributes like a
symbol and a value
2. Implement the Collection interface: De ne an interface with methods for adding cards, removing
cards, and nding cards by symbol.
3. Create a concrete implementation of the Collection interface: Implement the methods de ned in the
interface using appropriate data structures like lists or dictionaries to store the cards.
4. Provide a user interface: Create a user interface to interact with the program.
5. Users should be able to add cards, remove cards, and search for cards by symbol.
Program Code :
import java.util.*;
class Card {
String symbol;
fi
fi
fi
fi
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
int number;
@Override
public String toString() {
return symbol + " " + number;
}
}
Output :
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
4. Learning Outcomes :
4. Learnt about Hashing in java and its implementation to solve various problems.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Experiment- 3.2
1. Aim : Create an application for online auction using Servlet and JSP.
3. Procedure :
1. Begin by initiating a Dynamic Web Project in Eclipse IDE.
2. Develop a JSP le within the project.
3. Launch the Tomcat server and deploy the project.
4. Initiate a Dynamic Web Project.
5. Develop a JSP le.
6. 6. Launch the Tomcat server and deploy the project..
Program Code :
package com.company;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
fi
fi
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.*;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Vector;
public
class Admin {
private JButton startButton;
private JLabel timerLabel;
privateJPanel adminPanel;
private JButton ADDITEMButton;
Private JTable table1;
private JTextField nameData;
private JTextField priceData;
private JTextField path;
private JButton SELECTIMAGEButton;
private JLabel imageLabel;
private JButton CLOSEButton;
public static String adminNameData = "";
public static String adminPriceData = "";
public static ImageIcon adminImageData;
JFrame adminF = new JFrame();
Timer timer;
public static int sec = 60;
public Admin() {
adminF.setContentPane(adminPanel);
adminF.pack();
tableData();
adminF.setVisible(true);
startButton.addActionListener(new ActionListener() {
@Override public void actionPerformed(ActionEvent e) {
startTimer();
timer.start();
}
});
ADDITEMButton.addActionListener(new ActionListener() {
@Override public void actionPerformed(ActionEvent e) {
if (nameData.getText().equals("") || path.getText().equals("") ||
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
priceData.getText().equals("")) {
JOptionPane.showMessageDialog(
null, "Please Fill All Fields to add Record.”);
} else {
String sql = "insert into auction" + "(ITEM_NAME,IMAGE,PRICE)" + "values
(?,?,?)";
try {
File f = new File(path.getText());
InputStream inputStream = new FileInputStream(f);
Class.forName("com.mysql.cj.jdbc.Driver");
Connection connection = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/intern", "root", "root");
PreparedStatement statement = connection.prepareStatement(sql);
statement.setString(1, nameData.getText());
statement.setBlob(2, inputStream);
statement.setString(3, priceData.getText());
statement.executeUpdate();
JOptionPane.showMessageDialog(null, "DETAILS ADDED SUCCESSFULLY");
nameData.setText("");
priceData.setText("");
imageLabel.setIcon(null);
path.setText("");
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
}
tableData();
}
}
});
SELECTIMAGEButton.addActionListener(new ActionListener() {
@Override public void actionPerformed(ActionEvent e) {
JFileChooser fileChooser = new JFileChooser();
FileNameExtensionFilter filter =
new FileNameExtensionFilter("*.IMAGE", "jpg", "png");
fileChooser.addChoosableFileFilter(filter);
int rs = fileChooser.showSaveDialog(null);
if (rs == JFileChooser.APPROVE_OPTION) {
File selectedImage = fileChooser.getSelectedFile();
path.setText(selectedImage.getAbsolutePath());
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
imageLabel.setIcon(resize(path.getText()));
}
}
});
table1.addMouseListener(new MouseAdapter() {
public
void startTimer() {
timer = new Timer(
1000, new ActionListener() {
@Override public void actionPerformed(ActionEvent e) {
sec--;
if (sec == -1) {
timer.stop();
tableData();
} else if (sec >= 0 && sec < 10)
timerLabel.setText("00:0" + sec);
else
timerLabel.setText("00:" + sec);
}
});
}
public
void tableData() {
try {
String a = "Select* from auction";
Class.forName("com.mysql.cj.jdbc.Driver");
Connection connection = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/intern", "root", "root");
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery(a);
table1.setModel(buildTableModel(rs));
} catch (Exception ex1) {
JOptionPane.showMessageDialog(null, ex1.getMessage());
}
}
public
static DefaultTableModel buildTableModel(ResultSet rs) throws SQLException {
ResultSetMetaData metaData = rs.getMetaData();
// names of columns
Vector<String> columnNames = new Vector<String>();
int columnCount = metaData.getColumnCount();
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Output :
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
4. Learning Outcomes :
4. Learnt about Client-side and Server-side form validation to ensure data integrity.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Experiment- 3.3
3. Procedure :
1. Begin by initiating a Dynamic Web Project in Eclipse IDE.
2. Develop a JSP le within the project.
3. Launch the Tomcat server and deploy the project.
4. Initiate a Dynamic Web Project.
5. Develop a JSP le.
6. 6. Launch the Tomcat server and deploy the project..
Program Code :
<html>
<head>
<title>Simple Calculator</title>
</head>
<body>
<h2>Simple Calculator</h2>
<label for="num1">Enter first number:</label>
fi
fi
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
JSP Code :
package com.example;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
int result = 0;
if (operation.equals("add")) {
Output :
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
4. Learning Outcomes :
4. Learnt about Client-side and Server-side form validation to ensure data integrity.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Experiment- 1.3
1. Aim : Create an application to calculate interest for FDs, RDs based on certain conditions
using inheritance.
• Develop a program to create an application to make an Account holders list and calculate
interest for FDs, RDs based on certain conditions using inheritance.
Program Code :
import java.util.*;
double interestRate = 0;
double amount = 0;
double calculateInterest() {
System.out.println("Enter your savings amount: ");
amount = sc.nextDouble();
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
if (amount < 0) {
System.out.println("Enter the right amount.");
return 0;
}
if (n == 1) {
interestRate = amount * 4 / 100;
} else if (n == 2) {
interestRate = amount * 6 / 100;
} else {
System.out.println("Wrong choice.");
return 0;
}
return interestRate;
}
}
double interestRate;
double amount;
int noOfDays;
int ageOfACHolder;
double calculateInterest() {
System.out.println("Enter your FD amount: ");
amount = sc.nextDouble();
if (noOfDays < 0) {
System.out.println("Invalid number of days. Please enter correct details.");
return 0;
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
if (ageOfACHolder < 0) {
System.out.println("Invalid Age. Please enter correct details.");
return 0;
}
return interestRate;
}
}
double interestRate;
double amount;
int noOfMonths;
int ageOfACHolder;
double monthlyAmount;
double calculateInterest() {
System.out.println("Enter the monthly amount: ");
monthlyAmount = sc.nextDouble();
if (monthlyAmount < 0) {
System.out.println("Invalid Amount. Please Enter correct details.");
return 0;
}
if (noOfMonths <= 0) {
System.out.println("Invalid number of Months. Please Enter correct details.");
return 0;
}
if (ageOfACHolder <= 0) {
System.out.println("Invalid Age. Please Enter correct details.");
return 0;
} else if (ageOfACHolder >= 1 && ageOfACHolder <= 60) {
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
return interestRate;
}
}
class Experiment_3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {
System.out.println("\nSelect the option:\n1. Interest Calculator-SB\n2. Interest Calculator-FD\n3. Interest
Calculator-RD\n4. Exit\n");
int n = sc.nextInt();
switch (n) {
case 1:
double d1 = sb.calculateInterest();
System.out.println("Interest gained is: " + d1);
break;
case 2:
double d2 = fd.calculateInterest();
System.out.println("Interest gained is: " + d2);
break;
case 3:
double d3 = rd.calculateInterest();
System.out.println("Interest gained is: " + d3);
break;
case 4:
System.out.println("Thank you for using our services.");
sc.close();
System.exit(0);
default:
System.out.println("Wrong Choice, Enter again.");
break;
}
}
}
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Output :
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
4. Learning Outcomes :
4. Learnt about exception handling and use of try, catch and finally.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Experiment- 2.4
1. Aim : Create a menu-based Java application with the following options.1. Add an Employee
2. Display All 3.Exit If option 1 is selected, the application should gather details of the
employee like employee name, employee id, designation and salary and store it in a file. If
option 2 is selected, the application should display all the employee details. If option 3 is
selected the application should exit..
3. Procedure :
1. Create a class Employee to store its details like id, name ,salary, age, etc..
2. Create a EmployeeManager class where you ask for your choice using.
3. Add an employee.
4. Display All.
5. Exitt.
Program Code :
import java.io.*;
import java.util.LinkedList;
import java.util.Scanner;
@Override
public String toString() {
return "Employee{" +
"name='" + name + '\'' +
", id=" + id +
", designation='" + designation + '\'' +
", salary=" + salary +
'}';
}
}
break;
case 2:
displayAllEmployees();
break;
case 3:
saveEmployeeDataToFile();
running = false;
System.out.println("Exiting...");
break;
default:
System.out.println("Invalid choice!");
}
}
scanner.close();
}
Output :
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
4. Learning Outcomes :
Experiment- 1.2
1. Aim : To Design and implement a simple inventory control system for a small video rental
store.
• Develop a user-friendly and intuitive inventory control system for a small video rental store
that efficiently manages and tracks the store's video rental collection.
• Implement a secure and reliable database to store essential information about each video,
including title, genre, release date, and availability status, ensuring accurate and up-to-date
inventory records.
Program Code :
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public VideoRentalStore() {
this.inventory = new HashMap<>();
}
System.out.println("Added " + quantity + " copies of " + title + " to the inventory.");
}
switch (choice) {
case 1:
System.out.print("Enter movie title: ");
String title = scanner.nextLine();
System.out.print("Enter quantity: ");
int quantity = scanner.nextInt();
rentalStore.addMovie(title, quantity);
break;
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
case 2:
System.out.print("Enter movie title: ");
title = scanner.nextLine();
System.out.print("Enter quantity to rent: ");
quantity = scanner.nextInt();
rentalStore.rentMovie(title, quantity);
break;
case 3:
rentalStore.displayInventory();
break;
case 4:
System.out.println("Exiting program. Goodbye!");
System.exit(0);
default:
System.out.println("Invalid choice. Please enter a valid option.");
}
}
}
}
Output :
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
4. Learning Outcomes :
3. Learnt about basics of java and concepts of object oriented programming and its
implementation in java.
Experiment- 3.1
1. Aim : Create a palindrome creator application for making a longest possible palindrome out
of given input string.
2. Objective : Given a string, S, find its largest palindromic substring. Input Format: A string,
S. Constraints: 151000000. All the characters are lower-case English letters. Output Format:
Print the largest possible substring of S.
3. Procedure :
1. First, we need to consider the type of value.
2. If it is a number, we need to change it to a string to compare how it reads backwards and forwards.
3. If it is an object, we need to somehow also change it to a string to do a comparison.
4. If it is a string, we can forge ahead.
5. Compare a string with its reversed version.
6. Iterate using for loop and check to see if character on other side of string.
7. Use recursion to check the rst and last letters before invoking the function again with the shortened
string.
Program Code :
import java.util.Scanner;
Output :
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
4. Learning Outcomes :
Experiment- 2.2
1. Aim : Create a program to collect unique symbols from a set of cards using set interface.
2. Objective : Develop a program that utilizes the Collection interface to efficiently collect
and store all cards, enabling users to easily find and retrieve all cards associated with a given
symbol.
3. Procedure : To create a program that collects and stores all the cards to assist users in
finding all the cards in a given symbol using a Collection interface, you can follow these
steps :
1. De ne the Card class: Create a class to represent a single card. Each card should have attributes like a
symbol and a value
2. Implement the Collection interface: De ne an interface with methods for adding cards, removing
cards, and nding cards by symbol.
3. Create a concrete implementation of the Collection interface: Implement the methods de ned in the
interface using appropriate data structures like lists or dictionaries to store the cards.
4. Provide a user interface: Create a user interface to interact with the program.
5. Users should be able to add cards, remove cards, and search for cards by symbol.
Program Code :
import java.util.*;
class Card {
String symbol;
int number;
fi
fi
fi
fi
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
@Override
public String toString() {
return symbol + " " + number;
}
}
if (!symbolSet.contains(symbol)) {
symbolSet.add(symbol);
}
cardSet.add(card);
}
Output :
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
4. Learning Outcomes :
4. Learnt about Hashing in java and its implementation to solve various problems.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Experiment- 2.3
1. Aim : Write a Program to perform the basic operations like insert, delete, display and search
in list. List contains String object items where these operations are to be performed..
2. Objective : This program aims to create a string list manager, allowing users to insert,
delete, display, and search for specific strings within the list. This provides a basic framework
for manipulating and organizing string data.
3. Procedure :
1. ArrayList and Scanner: The program uses an ArrayList to store items and a Scanner to read user
input.
2. Menu Display: A menu is continuously displayed to the user until they choose to exit. The menu
includes options to insert, search, delete, display items, and exit the program.
3. Switch Statement: Depending on the user’s choice, different operations are performed. This is
managed using a switch statements.
4. Insert Operation: If the user chooses to insert an item, they are prompted to enter the item. The item is
then added to the ArrayList.
5. Search Operation: If the user chooses to search for an item, they are prompted to enter the item. The
program then checks if the item exists in the ArrayList.
6. Delete Operation: If the user chooses to delete an item, they are prompted to enter the item. The
program then attempts to remove the item from the ArrayList
7. Display Operation: If the user chooses to display the items, the program prints all the items in the
ArrayList.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Program Code :
import java.util.ArrayList;
import java.util.Scanner;
break;
case 4:
System.out.println("The Items in the list are : ");
for (String str : list) {
System.out.println(str);
}
break;
case 5:
System.out.println("Exiting...");
break;
default:
System.out.println("Invalid choice! Please enter a valid option.");
}
} while (choice != 5);
scanner.close();
}
}
Output :
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
4. Learning Outcomes :