0% found this document useful (0 votes)
38 views47 pages

Ilovepdf Merged

3.6

Uploaded by

rohitjangra7944
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views47 pages

Ilovepdf Merged

3.6

Uploaded by

rohitjangra7944
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment- 1.1

Student Name: Lakshay Sindhu UID: 21BCS10420


Branch: CSE Section/Group: 21BCS CC 28 - B
Semester: 6th (Sixth) Date of Performance: 18/01/24
Subject Name: Project Based Learning in Java Lab Subject Code: 21CSH-319

1. Aim : To Create an application to save the employee information using arrays.

2. Objective : To learn about arrays in java

To learn about usage of loops and switch statements.

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.

3. Code and Output :

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

String[] desigCodes = {"e", "c", "k", "r", "m"};


String[] desigNames = {"Engineer", "Consultant", "Clerk", "Receptionist", "Manager"};
int[] daAmounts = {20000, 32000, 12000, 15000, 40000};

boolean found = false;


for (String[] emp : empDetails) {
if (emp[0].equals(String.valueOf(empId))) {
found = true;
int basic = Integer.parseInt(emp[5]);
int hra = Integer.parseInt(emp[6]);
int it = Integer.parseInt(emp[7]);
int da = getDA(emp[3], desigCodes, daAmounts);
int salary = basic + hra + da - it;

String designation = getDesignation(emp[3], desigCodes, desigNames);

System.out.println("Emp No.\tEmp Name\tDepartment\tDesignation\tSalary");


System.out.println(emp[0] + "\t" + emp[1] + "\t\t" + emp[4] + "\t\t" + designation + "\t" + salary);
break;
}
}
System.out.println();

if (!found) {
System.out.println("There is no employee with empid: " + empId);
}
}

private static String getDesignation(String desigCode, String[] desigCodes, String[] desigNames) {


for (int i = 0; i < desigCodes.length; i++) {
if (desigCode.equals(desigCodes[i])) {
return desigNames[i];
}
}
return "Unknown";
}

private static int getDA(String desigCode, String[] desigCodes, int[] daAmounts) {


int index = -1;
for (int i = 0; i < desigCodes.length; i++) {
if (desigCode.equals(desigCodes[i])) {
index = i;
break;
}
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

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 :

1. Learnt about array and its implementation in java.

2. Learnt about various loops and switch case in java.

3. Learnt about basics of java and concepts of object oriented programming and its
implementation in java.

4. Learnt about different types of arrays such as jagged array.


DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Experiment- 2.1

Student Name: Lakshay Sindhu UID: 21BCS10420


Branch: CSE Section/Group: 21BCS CC 628 - B
Semester: 6th (Sixth) Date of Performance: 08/02/24
Subject Name: Project Based Learning in Java Lab Subject Code: 21CSH-319

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.

4. Code and Output :

Program Code :
import java.util.*;

class Card {
String symbol;
fi
fi
fi
fi
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
int number;

public Card(String symbol, int number) {


this.symbol = symbol;
this.number = number;
}

@Override
public String toString() {
return symbol + " " + number;
}
}

public class Experiment_4 {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println();
System.out.println("Enter Number of Cards : ");
int numCards = scanner.nextInt();
scanner.nextLine();
Map<String, List<Card>> cardsMap = new TreeMap<>();
for (int i = 0; i < numCards; i++) {
System.out.println("Enter card " + (i + 1) + ": ");
String symbol = scanner.nextLine();
int number = scanner.nextInt();
scanner.nextLine();
Card card = new Card(symbol, number);
cardsMap.computeIfAbsent(symbol, k -> new ArrayList<>()).add(card);
}
System.out.println("Distinct Symbols are : ");
for (String symbol : cardsMap.keySet()) {
System.out.print(symbol + " ");
}
System.out.println();
for (Map.Entry<String, List<Card>> entry : cardsMap.entrySet()) {
System.out.println("Cards in " + entry.getKey() + " Symbol");
List<Card> cards = entry.getValue();
int sum = 0;

for (Card card : cards) {


System.out.println(card);
sum += card.number;
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
}
System.out.println("Number of cards : " + cards.size());
System.out.println("Sum of Numbers : " + sum);
}
}
}

Output :
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

4. Learning Outcomes :

1. Learnt about collection in java.

2. Learnt about different collections in java.

3. Learnt about Hashset and Hashmap in java.

4. Learnt about Hashing in java and its implementation to solve various problems.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Experiment- 3.2

Student Name: Lakshay Sindhu UID: 21BCS10420


Branch: CSE Section/Group: 21BCS CC 628 - B
Semester: 6th (Sixth) Date of Performance: 28/03/24
Subject Name: Project Based Learning in Java Lab Subject Code: 21CSH-319

1. Aim : Create an application for online auction using Servlet and JSP.

2. Objective : To learn about Java Server Pages JSP.

• To learn about various JSP tags.

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..

4. Code and Output :

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() {

@Override public void mouseClicked(MouseEvent e) {


DefaultTableModel dm = (DefaultTableModel)table1.getModel();
int selectedRow = table1.getSelectedRow();
adminNameData = dm.getValueAt(selectedRow, 0).toString();
nameData.setText(adminNameData);
byte[] img = (byte[])dm.getValueAt(selectedRow, 1);
ImageIcon imageIcon = new ImageIcon(img);
Image im = imageIcon.getImage();
Image newimg = im.getScaledInstance(200, 200, Image.SCALE_SMOOTH);
ImageIcon finalPic = new ImageIcon(newimg);
adminImageData = finalPic;
imageLabel.setIcon(adminImageData);
adminPriceData = dm.getValueAt(selectedRow, 2).toString();
priceData.setText(adminPriceData);
}
});
CLOSEButton.addActionListener(new ActionListener() {
@Override public void actionPerformed(ActionEvent e) {
adminF.dispose();
}
});
}
public
ImageIcon resize(String path) {
ImageIcon myImg = new ImageIcon(path);
Image image = myImg.getImage();
Image newImage = image.getScaledInstance(200, 200, Image.SCALE_SMOOTH);
ImageIcon finalImage = new ImageIcon(newImage);
return finalImage;
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

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

for (int column = 1; column <= columnCount; column++) {


columnNames.add(metaData.getColumnName(column));
}
// data of the table
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
while (rs.next()) {
Vector<Object> vector = new Vector<Object>();
for (int columnIndex = 1; columnIndex <= columnCount; columnIndex++) {
vector.add(rs.getObject(columnIndex));
}
data.add(vector);
}
return new DefaultTableModel(data, columnNames);
}
}

Output :
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

4. Learning Outcomes :

1. Learnt about JSP(Java Server Pages) and Servlet in Java .

2. Learnt about servlet in java.

3. Learnt about managing data within web application.

4. Learnt about Client-side and Server-side form validation to ensure data integrity.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Experiment- 3.3

Student Name: Lakshay Sindhu UID: 21BCS10420


Branch: CSE Section/Group: 21BCS CC 628 - B
Semester: 6th (Sixth) Date of Performance: 04/04/24
Subject Name: Project Based Learning in Java Lab Subject Code: 21CSH-319

1. Aim : Create JSP application for addition, multiplication and division.

2. Objective : To learn about Java Server Pages JSP.

• To learn about various JSP tags.

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..

4. Code and Output :

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

<input type="number" id="num1" name="num1"><br><br>


<label for="num2">Enter second number:</label>
<input type="number" id="num2" name="num2"><br><br
<button onclick="add()">Add</button>
<button onclick="subtract()">Subtract</button>
<button onclick="multiply()">Multiply</button>
<button onclick="divide()">Divide</button><br><br>
<p id="result"></p>
<script> function add() {
var num1 = parseFloat(document.getElementById('num1').value);
var num2 = parseFloat(document.getElementById('num2').value);
var result = num1 + num2;
document.getElementById('result').innerHTML = 'Result: ' + result;
}
else {document.getElementById('result').innerHTML = 'Error: Division by zero!';
}}
</script>
</body>
</html>

JSP Code :
package com.example;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class CalculatorServlet extends HttpServlet {


protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
int num1 = Integer.parseInt(request.getParameter("num1"));
int num2 = Integer.parseInt(request.getParameter(“num2”));

String operation = request.getParameter(“operation");


DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

int result = 0;
if (operation.equals("add")) {

result = num1 + num2;


} else if (operation.equals("multiply")) {
result = num1 * num2;
} else if (operation.equals("divide")) {
if (num2 != 0) {
result = num1 / num2;
} else {
request.setAttribute("error", "Division by zero error!");
RequestDispatcher rd = request.getRequestDispatcher("calculator.jsp");
rd.forward(request, response);
return;
}
}
request.setAttribute("result", result);
RequestDispatcher rd = request.getRequestDispatcher("calculator.jsp");
rd.forward(request, response);
}
}

Output :
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

4. Learning Outcomes :

1. Learnt about JSP(Java Server Pages) and Servlet in Java .

2. Learnt about servlet in java.

3. Learnt about managing data within web application.

4. Learnt about Client-side and Server-side form validation to ensure data integrity.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Experiment- 1.3

Student Name: Lakshay Sindhu UID: 21BCS10420


Branch: CSE Section/Group: 21BCS CC 628 - B
Semester: 6th (Sixth) Date of Performance: 01/02/24
Subject Name: Project Based Learning in Java Lab Subject Code: 21CSH-319

1. Aim : Create an application to calculate interest for FDs, RDs based on certain conditions
using inheritance.

2. Objective : To learn about concept of Inheritance.

To learn about Abstract classes, Exception Handling.

• 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.

3. Code and Output :

Program Code :
import java.util.*;

abstract class Account {


double interestRate;
double amount;

abstract double calculateInterest();


}

class SBAccount extends Account {


Scanner sc = new Scanner(System.in);

double interestRate = 0;
double amount = 0;

double calculateInterest() {
System.out.println("Enter your savings amount: ");
amount = sc.nextDouble();
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

System.out.println("Enter the account type:\n1. Normal\n2. NRI “);


int n = sc.nextInt();

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;
}
}

class FDAccount extends Account {


Scanner sc = new Scanner(System.in);

double interestRate;
double amount;
int noOfDays;
int ageOfACHolder;

double aboveCrore(double amount1, int noOfDays) {


if (noOfDays >= 7 && noOfDays <= 14) {
return amount1 * 6.5 / 100;
} else if (noOfDays >= 15 && noOfDays <= 45) {
return amount1 * 6.75 / 100;
} else if (noOfDays >= 45 && noOfDays <= 60) {
return amount1 * 8 / 100;
} else if (noOfDays >= 61 && noOfDays <= 184) {
return amount1 * 8.5 / 100;
} else if (noOfDays >= 185 && noOfDays <= 365) {
return amount1 * 10 / 100;
} else return 0;
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

double belowCrore(double amount2, int noOfDays, int ageOfACHolder) {


if (ageOfACHolder <= 60) {
if (noOfDays >= 7 && noOfDays <= 14) {
return amount2 * 4.5 / 100;
}
else if (noOfDays >= 15 && noOfDays <= 29) {
return amount2 * 4.75 / 100;
} else if (noOfDays >= 30 && noOfDays <= 45) {
return amount2 * 5.5 / 100;
} else if (noOfDays >= 45 && noOfDays <= 60) {
return amount2 * 7 / 100;
} else if (noOfDays >= 61 && noOfDays <= 184) {
return amount2 * 7.5 / 100;
} else if (noOfDays >= 185 && noOfDays <= 365) {
return amount2 * 8 / 100;
} else return 0;
} else {
if (noOfDays >= 7 && noOfDays <= 14) {
return amount2 * 5 / 100;
} else if (noOfDays >= 15 && noOfDays <= 29) {
return amount2 * 5.25 / 100;
} else if (noOfDays >= 30 && noOfDays <= 45) {
return amount2 * 6 / 100;
} else if (noOfDays >= 45 && noOfDays <= 60) {
return amount2 * 7.5 / 100;
} else if (noOfDays >= 61 && noOfDays <= 184) {
return amount2 * 8 / 100;
} else if (noOfDays >= 185 && noOfDays <= 365) {
return amount2 * 8.5 / 100;
} else return 0;
}
}

double calculateInterest() {
System.out.println("Enter your FD amount: ");
amount = sc.nextDouble();

System.out.println("Enter the number of days: ");


noOfDays = sc.nextInt();

if (noOfDays < 0) {
System.out.println("Invalid number of days. Please enter correct details.");
return 0;
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

System.out.println("Enter your Age: ");


ageOfACHolder = sc.nextInt();

if (ageOfACHolder < 0) {
System.out.println("Invalid Age. Please enter correct details.");
return 0;
}

if (amount >= 0 && amount <= 10000000) {


interestRate = belowCrore(amount, noOfDays, ageOfACHolder);
} else if (amount > 10000000) {
interestRate = aboveCrore(amount, noOfDays);
} else {
System.out.println("Enter the right amount.");
return 0;
}

return interestRate;
}
}

class RDAccount extends Account {


Scanner sc = new Scanner(System.in);

double interestRate;
double amount;
int noOfMonths;
int ageOfACHolder;
double monthlyAmount;

double general(double monthly, double months) {


if (months > 0 && months <= 6) {
return monthly * months * (months + 1) * 7.5 / 2400;
} else if (months > 6 && months <= 9) {
return monthly * months * (months + 1) * 7.75 / 2400;
} else if (months > 9 && months <= 12) {
return monthly * months * (months + 1) * 8 / 2400;
} else if (months > 12 && months <= 15) {
return monthly * months * (months + 1) * 8.25 / 2400;
} else if (months > 15 && months <= 18) {
return monthly * months * (months + 1) * 8.5 / 2400;
} else if (months > 18 && months <= 21) {
return monthly * months * (months + 1) * 8.75 / 2400;
} else return 0;
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

double senior(double monthly, double months) {


if (months > 0 && months <= 6) {
return monthly * months * (months + 1) * 8 / 2400;
} else if (months > 6 && months <= 9) {
return monthly * months * (months + 1) * 8.25 / 2400;
} else if (months > 9 && months <= 12) {
return monthly * months * (months + 1) * 8.5 / 2400;
} else if (months > 12 && months <= 15) {
return monthly * months * (months + 1) * 8.75 / 2400;
} else if (months > 15 && months <= 18) {
return monthly * months * (months + 1) * 9 / 2400;
} else if (months > 18 && months <= 21) {
return monthly * months * (months + 1) * 9.25 / 2400;
} else return 0;

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;
}

System.out.println("Enter the number of months: ");


noOfMonths = sc.nextInt();

if (noOfMonths <= 0) {
System.out.println("Invalid number of Months. Please Enter correct details.");
return 0;
}

amount = monthlyAmount * noOfMonths;

System.out.println("Enter your Age: ");


ageOfACHolder = sc.nextInt();

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

interestRate = general(monthlyAmount, noOfMonths);


} else interestRate = senior(monthlyAmount, noOfMonths);

return interestRate;
}
}

class Experiment_3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

SBAccount sb = new SBAccount();


FDAccount fd = new FDAccount();
RDAccount rd = new RDAccount();

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 :

1. Learnt about inheritance in java and its implementation.

2. Learnt about different types of inheritance.

3. Learnt about abstract class in java and its uses.

4. Learnt about exception handling and use of try, catch and finally.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Experiment- 2.4

Student Name: Lakshay Sindhu UID: 21BCS10420


Branch: CSE Section/Group: 21BCS CC 628 - B
Semester: 6th (Sixth) Date of Performance: 07/03/24
Subject Name: Project Based Learning in Java Lab Subject Code: 21CSH-319

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..

2. Objective : To learn about concept of Linked List in Java.

• To Learn about the concept of File Handling in Java.

• To Learn about the concept of Exception Handling in Java.

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.

4. Code and Output :

Program Code :
import java.io.*;
import java.util.LinkedList;
import java.util.Scanner;

class Employee implements Serializable {


private static final long serialVersionUID = 1L;
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

private String name;


private int id;
private String designation;
private double salary;

public Employee(String name, int id, String designation, double salary) {


this.name = name;
this.id = id;
this.designation = designation;
this.salary = salary;
}

@Override
public String toString() {
return "Employee{" +
"name='" + name + '\'' +
", id=" + id +
", designation='" + designation + '\'' +
", salary=" + salary +
'}';
}
}

public class EmployeeManagement {


private static final String FILE_NAME = "employee_data.dat";
private static LinkedList<Employee> employeeList = new LinkedList<>();

public static void main(String[] args) {


loadEmployeeDataFromFile();
Scanner scanner = new Scanner(System.in);
boolean running = true;
while (running) {
System.out.println("\nSelect an option:");
System.out.println("1. Add an Employee");
System.out.println("2. Display All");
System.out.println("3. Exit");
int choice = scanner.nextInt();
scanner.nextLine(); // Consume the newline character
switch (choice) {
case 1:
addEmployee(scanner);
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

break;
case 2:
displayAllEmployees();
break;
case 3:
saveEmployeeDataToFile();
running = false;
System.out.println("Exiting...");
break;
default:
System.out.println("Invalid choice!");
}
}
scanner.close();
}

private static void addEmployee(Scanner scanner) {


System.out.println("Enter Employee Name:");
String name = scanner.nextLine();
System.out.println("Enter Employee ID:");
int id = scanner.nextInt();
scanner.nextLine(); // Consume the newline character
System.out.println("Enter Employee Designation:");
String designation = scanner.nextLine();
System.out.println("Enter Employee Salary:");
double salary = scanner.nextDouble();
scanner.nextLine(); // Consume the newline character
Employee employee = new Employee(name, id, designation, salary);
employeeList.add(employee);
System.out.println("Employee added successfully.");
}

private static void displayAllEmployees() {


if (employeeList.isEmpty()) {
System.out.println("No employees to display.");
} else {
System.out.println("Employee details:");
for (Employee employee : employeeList) {
System.out.println(employee);
}
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
}

private static void loadEmployeeDataFromFile() {


try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(FILE_NAME))) {
employeeList = (LinkedList<Employee>) ois.readObject();
System.out.println("Employee data loaded successfully.");
} catch (FileNotFoundException e) {
System.out.println("No previous data found. Starting fresh.");
} catch (IOException | ClassNotFoundException e) {
System.out.println("Error loading employee data from file: " +
e.getMessage());
}
}

private static void saveEmployeeDataToFile() {


try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(FILE_NAME))) {
oos.writeObject(employeeList);
System.out.println("Employee data saved successfully.");
} catch (IOException e) {
System.out.println("Error saving employee data to file: " + e.getMessage());
}
}
}

Output :
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

4. Learning Outcomes :

1. Learnt about LinkedList in java.

2. Learnt about Serialisation in java.

3. Learnt about advantages of LinkedList over Array.

4. Learnt about difference between ArrayList and Linked List.


DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Experiment- 1.2

Student Name: Lakshay Sindhu UID: 21BCS10420


Branch: CSE Section/Group: 21BCS CC 628 - B
Semester: 6th (Sixth) Date of Performance: 25/01/24
Subject Name: Project Based Learning in Java Lab Subject Code: 21CSH-319

1. Aim : To Design and implement a simple inventory control system for a small video rental
store.

2. Objective : To learn about Classes.

To learn about Encapsulation, Aggregation concept in java.

• 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.

3. Code and Output :

Program Code :
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class VideoRentalStore {


private Map<String, Integer> inventory;

public VideoRentalStore() {
this.inventory = new HashMap<>();
}

public void addMovie(String title, int quantity) {


inventory.put(title, quantity);
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

System.out.println("Added " + quantity + " copies of " + title + " to the inventory.");
}

public void rentMovie(String title, int quantity) {


if (inventory.containsKey(title)) {
int availableCopies = inventory.get(title);
if (availableCopies >= quantity) {
inventory.put(title, availableCopies - quantity);
System.out.println("Rented " + quantity + " copies of " + title + ".");
} else {
System.out.println("Sorry, not enough copies of " + title + " available.");
}
} else {
System.out.println("Movie not found in the inventory.");
}
}

public void displayInventory() {


System.out.println("Current Inventory:");
for (Map.Entry<String, Integer> entry : inventory.entrySet()) {
System.out.println(entry.getKey() + ": " + entry.getValue() + " copies");
}
}

public static void main(String[] args) {


VideoRentalStore rentalStore = new VideoRentalStore();
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("\nMenu:\n1. Add Movie\n2. Rent Movie\n3. Display Inventory\n4.Exit");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
scanner.nextLine();

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 :

1. Learnt about fundamentals of java and its implementation.

2. Learnt how to implement an inventory management system using object oriented


programming concepts.

3. Learnt about basics of java and concepts of object oriented programming and its
implementation in java.

4. Learnt about concept of database design and management.


DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Experiment- 3.1

Student Name: Lakshay Sindhu UID: 21BCS10420


Branch: CSE Section/Group: 21BCS CC 628 - B
Semester: 6th (Sixth) Date of Performance: 14/03/24
Subject Name: Project Based Learning in Java Lab Subject Code: 21CSH-319

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.

4. Code and Output :

Program Code :
import java.util.Scanner;

public class LongestPalindrome {


public String longestPalindrome(String s) {
if (s == null || s.length() < 1)
return “";
fi
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

int start = 0, end = 0;


for (int i = 0; i < s.length(); i++) {
int len1 = expandAroundCenter(s, i, i);
int len2 = expandAroundCenter(s, i, i + 1);
int len = Math.max(len1, len2);
if (len > end - start) {
start = i - (len - 1) / 2;
end = i + len / 2;
}
}
return s.substring(start, end + 1);
}

private int expandAroundCenter(String s, int left, int right) {


while (left >= 0 && right < s.length() && s.charAt(left) == s.charAt(right)) {
left--;
right++;
}
return right - left - 1;
}

public static void main(String[] args) {


LongestPalindrome p = new LongestPalindrome();
Scanner scanner = new Scanner(System.in);
System.out.println("Enter a string:");
String input = scanner.nextLine();
System.out.println("The longest palindromic substring is: " + p.longestPalindrome(input));
}
}

Output :
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

4. Learning Outcomes :

1. Learnt about Palindrome in java.

2. Learnt about recursion in java.

3. Learnt about dynamic programming.

4. Learnt about Longest Common Subsequence.


DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Experiment- 2.2

Student Name: Lakshay Sindhu UID: 21BCS10420


Branch: CSE Section/Group: 21BCS CC 628 - B
Semester: 6th (Sixth) Date of Performance: 22/02/24
Subject Name: Project Based Learning in Java Lab Subject Code: 21CSH-319

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.

4. Code and Output :

Program Code :
import java.util.*;

class Card {
String symbol;
int number;
fi
fi
fi
fi
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

public Card(String symbol, int number) {


this.symbol = symbol;
this.number = number;
}

@Override
public String toString() {
return symbol + " " + number;
}
}

public class Exp_5 {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Set<Card> cardSet = new HashSet<>();
Set<String> symbolSet = new HashSet<>();

while (symbolSet.size() < 4) {


System.out.println("Enter a card:");
String symbol = scanner.nextLine();
int number = Integer.parseInt(scanner.nextLine());
Card card = new Card(symbol, number);

if (!symbolSet.contains(symbol)) {
symbolSet.add(symbol);
}
cardSet.add(card);
}

System.out.println("Four symbols gathered in " + cardSet.size() + " cards.");


System.out.println("Cards in Set are:");

List<Card> sortedCards = new ArrayList<>(cardSet);


Collections.sort(sortedCards, Comparator.comparing(card -> card.symbol));

for (Card card : sortedCards) {


System.out.println(card);
}
scanner.close()
}
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Output :
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

4. Learning Outcomes :

1. Learnt about collection in java.

2. Learnt about different collections in java.

3. Learnt about Hashset and Hashmap in java.

4. Learnt about Hashing in java and its implementation to solve various problems.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

Experiment- 2.3

Student Name: Lakshay Sindhu UID: 21BCS10420


Branch: CSE Section/Group: 21BCS CC 628 - B
Semester: 6th (Sixth) Date of Performance: 29/02/24
Subject Name: Project Based Learning in Java Lab Subject Code: 21CSH-319

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

4. Code and Output :

Program Code :
import java.util.ArrayList;
import java.util.Scanner;

public class Main {


public static void main(String[] args) {
ArrayList<String> list = new ArrayList<>();
Scanner scanner = new Scanner(System.in);
int choice;
do {
System.out.println("Lakshay Sindhu, 21BCS10420");
System.out.println("1. Insert\n2. Search\n3. Delete\n4. Display\n5. Exit");
System.out.println("Enter your choice : ");
choice = scanner.nextInt();
scanner.nextLine();
switch (choice) {
case 1:
System.out.println("Enter the item to be inserted: ");
String item = scanner.nextLine();
list.add(item);
System.out.println("Inserted successfully");
break;
case 2:
System.out.println("Enter the item to search : ");
item = scanner.nextLine();
if (list.contains(item)) {
System.out.println("Item found in the list.");
} else {
System.out.println("Item not found in the list.");
}
break;
case 3:
System.out.println("Enter the item to delete : ");
item = scanner.nextLine();
if (list.remove(item)) {
System.out.println("Deleted successfully");
} else {
System.out.println("Item does not exist.");
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

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 :

1. Learnt about ArrayList in java.

2. Learnt about different methods of ArrayList in java.

3. Learnt about advantages of ArrayList over Array.

4. Learnt about difference between ArrayList and Linked List.

You might also like