java 1 A
java 1 A
UID: 22BCS12195
Section: IOT-644
Group: B
INDEX
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
Algorithm:
Step 1: Initialize the 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;
void displayEmployee() {
System.out.printf("ID: %d, Name: %s, Department: %s, Salary: %.2f\n", id, name,
department, salary);
}
}
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
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:
Experiment 1.2
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:
• Customer Class:
• 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;
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
@Override
public String toString() {
return "Title: " + title + " | Available: " + (isAvailable ? "Yes" : "No");
}
}
public VideoStore() {
inventory = new ArrayList<>();
}
// Rent a video
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
// 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.");
}
}
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");
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