UNIVERSITY INSTITUTE OF ENGINEERING
Department of Computer Science & Engineering
(BE-CSE/IT-6th Sem)
Subject Name: Project Based Learning In Java With Lab
Subject Code: 22CSH-359
Submitted to: Submitted by:
Kirat Kaur (E12999) Name: Samir Sonboir
UID: 22BCS12163
Section: IOT-644
Group: B
INDEX
Name: Samir Sonboir UID: 22BCS12163
Ex. Name of Experiments Date Conduct Viva Worksheet Total Remarks Signature
No (MM: 12) (MM: 10) (Record) (MM: 30) (with date)
(MM: 8)
Create an application to
1 save employee
information using arrays.
Design and implement a
2 simple inventory control
system for a small video
rental store.
Create an application to
3 calculate interest for FDs,
RDs based on certain
conditions using
inheritance.
Write a Program to
4 perform the basic
operations like insert,
delete, display and search
in list. List contains String
object items.
Create a program to
5 collect and store all the
cards to assist the users in
finding all the cards in a
given symbol using
Collection interface.
Create a program to
6 collect unique symbols
from a set of cards using
set interface.
Create a menu-based Java
7 application with the
following options. 1.Add
an Employee 2. Display
All 3. Exit.
Create JSP application for
8 addition, multiplication
and division.
9 Create an application for
online auction using
Servlet and JSP.
10
Lab Based Mini Project
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Experiment 1.1
Student Name: Samir Sonboir UID: 22BCS12163
Branch: CSE Section: IOT-644
Semester: 6th DOP: 20-01-25
Subject: Java Subject Code:22CSH-359
Aim: Create an application to save employee information using arrays.
Objective: To develop a functional application that effectively utilizes arrays to
store, manage, and retrieve employee information, enabling efficient data
organization and manipulation within the application.
Algorithm:
Step 1: Initialize the Program
• Start the program.
• Define an array of structures to store employee information.
• Each structure will include fields such as Employee ID, Name, Age, and Department.
Step 2: Define Functions
1. Add Employee Information:
o Prompt the user to enter details for an employee (ID, Name, Age, Department).
o Store the entered details in the next available position in the array.
o Check for array overflow (i.e., maximum number of employees).
2. Display All Employee Information:
o Iterate through the array and print all stored employee details.
o Handle cases where no employees are stored.
3. Search for an Employee:
o Prompt the user to enter the Employee ID.
o Search the array for a matching ID.
o Display the employee's details if found, otherwise print a message indicating the
ID is not found.
4. Exit Application:
o Provide an option to exit the program.
Step 3: Display Menu
• Display a menu with options to:
1. Add Employee
2. View All Employees
3. Search for an Employee
4. Exit
Step 4: Handle User Input
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
• Use a loop to repeatedly display the menu and prompt the user for a choice.
• Call the appropriate function based on the user's selection.
• Ensure input validation for numeric values and string lengths.
Step 5: Terminate Program
• Exit the loop when the user selects the Exit option.
Code:
import java.util.Scanner;
class Employee {
int id;
String name;
String department;
double salary;
Employee(int id, String name, String department, double salary) {
this.id = id;
this.name = name;
this.department = department;
this.salary = salary;
}
void displayEmployee() {
System.out.printf("ID: %d, Name: %s, Department: %s, Salary: %.2f\n", id, name,
department, salary);
}
}
public class EmployeeManagement {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the number of employees: ");
int n = scanner.nextInt();
scanner.nextLine(); // consume newline
Employee[] employees = new Employee[n];
int count = 0;
while (true) {
System.out.println("\nMenu:");
System.out.println("1. Add Employee");
System.out.println("2. Display Employees");
System.out.println("3. Exit");
System.out.print("Choose an option: ");
int choice = scanner.nextInt();
scanner.nextLine(); // consume newline
switch (choice) {
case 1:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
if (count < n) {
System.out.print("Enter Employee ID: ");
int id = scanner.nextInt();
scanner.nextLine(); // consume newline
System.out.print("Enter Employee Name: ");
String name = scanner.nextLine();
System.out.print("Enter Employee Department: ");
String department = scanner.nextLine();
System.out.print("Enter Employee Salary: ");
double salary = scanner.nextDouble();
employees[count] = new Employee(id, name, department, salary);
count++;
System.out.println("Employee added successfully!");
} else {
System.out.println("Employee array is full!");
}
break;
case 2:
if (count == 0) {
System.out.println("No employees to display.");
} else {
System.out.println("\nEmployee Details:");
for (int i = 0; i < count; i++) {
employees[i].displayEmployee();
}
}
break;
case 3:
System.out.println("Exiting program. Goodbye!");
scanner.close();
return;
default:
System.out.println("Invalid choice. Please try again.");
}
}
}
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Output:
Learning Outcomes:
1. Demonstrate: Apply key concepts to real-world scenarios to showcase understanding.
2. Analyze: Critically evaluate information, identify patterns, and draw meaningful
conclusions.
3. Create: Develop original work, including presentations, reports, or projects, to exhibit
comprehension and skills.
4. Communicate: Convey ideas and findings effectively through oral and written
communication.
5. Collaborate: Contribute to group projects and exhibit strong teamwork capabilities in a
collaborative environment.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Experiment 1.2
Student Name: Samir Sonboir UID: 22BCS12163
Branch: CSE Section: IOT-644 B
Semester: 6th DOP: 20-01-25
Subject: Java Subject Code: 22CSH-359
Aim: Design and implement a simple inventory control system for a small video rental store
Objective: To design and implement a user-friendly inventory control system for a small
video rental store, enabling efficient management of video inventory, including functionalities
for adding, renting, and returning videos.
Algorithm:
• Define Classes:
• Video: To represent each video, with attributes such as video ID, title, genre, and
availability status.
• Inventory: To manage the list of videos, including adding and removing videos from
the inventory.
• Customer: To represent customers, with attributes such as customer ID, name, and
rented videos.
• RentalSystem: To control the process of renting and returning videos.
• Video Class:
• Define the video with attributes such as videoID, title, genre, and isAvailable.
• Define methods to mark the video as rented and returned.
• Inventory Class:
• Maintain a list of videos (ArrayList<Video>).
• Implement methods to add new videos, display available videos, and check if a video
is available.
• Customer Class:
• Define a list to store rented videos.
• Implement methods to rent a video (if available) and return it.
• RentalSystem Class:
• Handle the main functionality: list available videos, allow customers to rent and return
videos, and display the inventory status.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Code:
import java.util.ArrayList;
import java.util.Scanner;
// Class representing a Video
class Video {
private String title;
private boolean isAvailable;
public Video(String title) {
this.title = title;
this.isAvailable = true;
}
public String getTitle() {
return title;
}
public boolean isAvailable() {
return isAvailable;
}
public void rent() {
if (isAvailable) {
isAvailable = false;
} else {
System.out.println("Error: Video is already rented out.");
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
public void returnVideo() {
if (!isAvailable) {
isAvailable = true;
} else {
System.out.println("Error: Video was not rented.");
}
}
@Override
public String toString() {
return "Title: " + title + " | Available: " + (isAvailable ? "Yes" : "No");
}
}
// Class representing the Video Store
class VideoStore {
private ArrayList<Video> inventory;
public VideoStore() {
inventory = new ArrayList<>();
}
// Add a new video to the inventory
public void addVideo(String title) {
for (Video video : inventory) {
if (video.getTitle().equalsIgnoreCase(title)) {
System.out.println("Error: Video already exists in the inventory.");
return;
}
}
inventory.add(new Video(title));
System.out.println("Video added successfully: " + title);
}
// List all videos in the inventory
public void listInventory() {
if (inventory.isEmpty()) {
System.out.println("No videos in inventory.");
} else {
System.out.println("Inventory:");
for (int i = 0; i < inventory.size(); i++) {
System.out.println((i + 1) + ". " + inventory.get(i));
}
}
}
// Rent a video
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
public void rentVideo(String title) {
for (Video video : inventory) {
if (video.getTitle().equalsIgnoreCase(title)) {
if (video.isAvailable()) {
video.rent();
System.out.println("You rented: " + title);
} else {
System.out.println("Video is currently unavailable.");
}
return;
}
}
System.out.println("Error: Video not found in inventory.");
}
// Return a video
public void returnVideo(String title) {
for (Video video : inventory) {
if (video.getTitle().equalsIgnoreCase(title)) {
if (!video.isAvailable()) {
video.returnVideo();
System.out.println("You returned: " + title);
} else {
System.out.println("Error: Video was not rented.");
}
return;
}
}
System.out.println("Error: Video not found in inventory.");
}
}
// Main class to run the Video Rental System
public class VideoRentalSystem {
public static void main(String[] args) {
VideoStore store = new VideoStore();
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("\n--- Video Rental Store ---");
System.out.println("1. Add Video");
System.out.println("2. List Inventory");
System.out.println("3. Rent Video");
System.out.println("4. Return Video");
System.out.println("5. Exit");
System.out.print("Enter your choice: ");
// Handle invalid input for menu choices
int choice = -1;
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
if (scanner.hasNextInt()) {
choice = scanner.nextInt();
} else {
System.out.println("Invalid choice. Please enter a number.");
scanner.next(); // Consume invalid input
continue;
}
scanner.nextLine();
switch (choice) {
case 1:
System.out.print("Enter video title to add: ");
String titleToAdd = scanner.nextLine().trim();
store.addVideo(titleToAdd);
break;
case 2:
store.listInventory();
break;
case 3:
System.out.print("Enter video title to rent: ");
String titleToRent = scanner.nextLine().trim();
store.rentVideo(titleToRent);
break;
case 4:
System.out.print("Enter video title to return: ");
String titleToReturn = scanner.nextLine().trim();
store.returnVideo(titleToReturn);
break;
case 5:
System.out.println("Exiting the system. Goodbye!");
scanner.close();
return;
default:
System.out.println("Invalid choice. Please try again.");
}
}
}
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Output:
Learning Outcomes:
• Object-Oriented Design: Learn to create and use classes for real-world entities.
• Core Programming Skills: Practice loops, conditionals, and methods for inventory
operations.
• Data Structure Usage: Use ArrayList to manage dynamic data effectively.
• User-Friendly Systems: Design intuitive interfaces and handle errors smoothly.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING