UNIVERSITY INSTITUTE OF ENGINEERING
Department of Computer Science & Engineering
(BE-CSE/IT-6th Sem)
Project Based Learning in Java with Lab
21CSH-319/21ITH-319
Submitted To: Submitted By:
Er. Gurleen Kaur Name: Abhishek Kumar
UID: 22BCS80201
Section: 634
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 a application to
1.1 save the employee
information using arrays.
Design and implement a
1.2 simple inventory control
system for a small video
rental store.
Create a application to
1.3 calculate interest for FDs,
RDs based on certain
conditions using
inheritance.
Create a program to
2.1 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
2.2 collect unique symbols
from a set of cards using
set interface.
Write a Program to
2.3 perform the basic
operations like insert,
delete, display and search
in list. List contains String
object items where these
operations are to be
performed.
Create a menu-based Java
2.4 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.1 Create a palindrome
creator application for
making a longest possible
palindrome out of given
input string.
3.2 Create JSP application for
addition, multiplication
and division.
Create an application for
3.3 online auction using
Servlet and JSP.
Experiment1.1
Student Name: Abhishek Kumar UID: 22BCS80201
Branch: BE-CSE Section/Group: CC_634-B
Semester: 6 Date of Performance: / /2024
Subject Name: Java Lab
Subject Code:21CSH-319
1. Aim: Create a application to save the employee information using arrays
2. Objective: 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. Algo. /Approach and output:
//Abhishek_22BCS80201
package experiment;
import java.util.Scanner;
class Employee {
int empNo;
String empName;
String joinDate;
char desigCode;
String dept;
int basic;
int hra;
int it;
public Employee(int empNo, String empName, String joinDate, char
desigCode, String dept, int basic, int hra, int it) {
this.empNo = empNo;
this.empName = empName;
this.joinDate = joinDate;
this.desigCode = desigCode;
this.dept = dept;
this.basic = basic;
this.hra = hra;
this.it = it;
}
public int getEmpNo() {
return empNo;
}
public String getEmpName() {
return empName;
}
public char getDesigCode() {
return desigCode;
}
public String getDept() {
return dept;
}
public int getSalary() {
int da = 0;
switch (desigCode) {
case 'e':
da = 20000;
break;
case 'c':
da = 32000;
break;
case 'k':
da = 12000;
break;
case 'r':
da = 15000;
break;
case 'm':
da = 40000;
break;
default:
da = 0;
break;
}
return basic + hra + da - it;
}
public String getDesignation() {
String desig = "";
switch (desigCode) {
case 'e':
desig = "Engineer";
break;
case 'c':
desig = "Consultant";
break;
case 'k':
desig = "Clerk";
break;
case 'r':
desig = "Receptionist";
break;
case 'm':
desig = "Manager";
break;
default:
desig = "Unknown";
break;
}
return desig;
}
}
public class Experiment1 {
public static void main(String[] args) {
//Initialize the array
Employee[] employees = new Employee[7];
employees[0] = new Employee(1001, "Ashish", "01/04/2009", 'e', "R&D",
20000, 8000, 3000);
employees[1] = new Employee(1002, "Sushma", "23/08/2012", 'c', "PM",
30000, 12000, 9000);
employees[2] = new Employee(1003, "Rahul", "12/11/2008", 'k', "Acct",
10000, 8000, 1000);
employees[3] = new Employee(1004, "Chahat", "29/01/2013", 'r', "Front
Desk", 12000, 6000, 2000);
employees[4] = new Employee(1005, "Ranjan", "16/07/2005", 'm',
"Engg", 50000, 20000, 20000);
employees[5] = new Employee(1006, "Suman", "1/1/2000", 'e',
"Manufacturing", 23000, 9000, 4400);
employees[6] = new Employee(1007, "Tanmay", "12/06/2006", 'c', "PM",
29000, 12000, 10000);
//Create a scanner object to read input from the command prompt
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Employee Id: ");
int empId = sc.nextInt();
sc.close();
// Find the employee with the given id in the array
Employee emp = null;
for (int i=0; i<employees.length; i++) {
if (employees[i].getEmpNo() == empId) {
emp = employees[i];
break;
}
}
if (emp == null) {
System.out.println("No Employee with empid: " + empId);
} else {
System.out.println("Emp No. Emp Name Department Designation
Salary");
System.out.println(emp.getEmpNo() + " " + emp.getEmpName() + " " +
emp.getDept() + " " + emp.getDesignation() + " " + emp.getSalary());
}
}
}
Output:
Experiment 1.2
Student Name: Abhishek Kumar UID: 22BCS80201
Branch: BE-CSE Section/Group: CC_634-B
Semester: 6 Date of Performance: / /2024
Subject Name: Java Lab Subject Code:21CSH-319
4. Aim: Design and implement a simple inventory control system for a small
video rental store.
5. Objective: The goal of this project is to design and implement a simple
inventory control system for a small video rental store. Define least two classes:
a class Video to model a video and a class VideoStore to model the actual store.
6. Algo. /Approach:
Video Class:
• Represents a video with attributes such as videoName, rating, and
checkOut status.
• Methods allow getting and setting attributes, checking out and returning
videos, and adding ratings.
• Overrides toString(), equals(Object o), and hashCode() methods.
VideoStore Class:
• Represents a video store with a fixed-size array of Video objects.
• Provides methods for adding videos, checking out, returning, adding
ratings, and listing inventory.
• Overrides toString(), equals(Object o), and hashCode() methods.
VideoLauncher Class:
• Acts as the main class, offering a menu-driven interface for interacting
with the video store.
• Uses Scanner for user input and a loop for continuous interaction.
• Users can add videos, check out, return, add ratings, and list the
inventory.
• The loop continues until the user chooses to exit.
7. Code and Output:
Video Class
// Abhishek_22BCS80201
package project;
import java.util.Objects;
public class Video {
private String videoName;
private int rating;
private boolean checkOut;
public String getVideoName() { //returns the name of the video.
return videoName;
}
public int getRating() { //returns the Rating of the video.
return rating;
}
public boolean isCheckOut() { //returns the checkOut status.
return checkOut;
}
public void setRating(int rating) { //sets the rating of the video.
this.rating = rating;
}
public void doCheckOut() { //allow the customer to rent a video.
System.out.println("Thank you for renting.");
}
public void doReturn() { //allows the customer to return the video.
System.out.println("Thank you for returning " + getVideoName() + "
.");
}
public void setCheckOut(boolean checkOut) { //Checkout Status of the
video.
this.checkOut = checkOut;
}
public void setVideoName(String videoName) { //sets the Video Name of
the file.
this.videoName = videoName;
}
public Video() {
this.videoName = "No-Name";
this.rating = 0;
this.checkOut = false;
}
public Video(String videoName, int rating, boolean checkOut) {
this.videoName = videoName;
this.rating = rating;
this.checkOut = checkOut;
}
public Video(String videoName) {
this.videoName = videoName;
rating = 3;
checkOut = false;
}
@Override
public String toString() { //This method provides ease in printing the
details of the object of the class
return "Video{" +
"videoName='" + videoName + '\'' +
", rating=" + rating +
", checkOut=" + checkOut +
'}';
}
@Override
public boolean equals(Object o) { //helps in comparing two instances of
the Video class.
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Video video = (Video) o;
return getRating() == video.getRating() && isCheckOut() ==
video.isCheckOut() && Objects.equals(getVideoName(),
video.getVideoName());
}
@Override
public int hashCode() { //returns the hashcode of the fields in the video
class.
return Objects.hash(getVideoName(), getRating(), isCheckOut());
}
}
Video Launcher Class:
//Abhishek kumar_22BCS80201
package project;
import java.util.Scanner;
public class VideoLauncher {
private static final int ADD_VIDEO = 1;
private static final int CHECK_OUT_VIDEO = 2;
private static final int RETURN_VIDEO = 3;
private static final int RECEIVE_RATING = 4;
private static final int LIST_INVENTORY = 5;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int customerInput;
VideoStore myVideoStore = new VideoStore();
String videoName;
int videoRating;
do {
System.out.println("Home");
System.out.println("----------");
System.out.println("1. Add video in Store : ");
System.out.println("2. Check out video : ");
System.out.println("3. Return video : ");
System.out.println("4. Receive Rating : ");
System.out.println("5. List Inventory : ");
System.out.println("Enter your choice (From 1-5) : ");
customerInput = sc.nextInt();
switch (customerInput) {
case ADD_VIDEO -> {
System.out.println("Enter the name of the video you want to
add...");
sc.nextLine();
videoName = sc.nextLine();
myVideoStore.addVideo(videoName);
}
case CHECK_OUT_VIDEO -> {
System.out.println("Enter the name of the video you want to
checkout...");
sc.nextLine();
videoName = sc.nextLine();
myVideoStore.doCheckOut(videoName);
}
case RETURN_VIDEO -> {
System.out.println("Enter the name of the video you want to
return...");
sc.nextLine();
videoName = sc.nextLine();
myVideoStore.doReturn(videoName);
}
case RECEIVE_RATING -> {
System.out.println("Enter the name of the video whose rating
you want to add...");
sc.nextLine();
videoName = sc.nextLine();
System.out.println("Enter the rating: ");
videoRating = sc.nextInt();
myVideoStore.recieveRating(videoName, videoRating);
}
case LIST_INVENTORY -> myVideoStore.listInventory();
default -> System.out.println("This is an Invalid Input!");
}
} while (customerInput != 6);
sc.close();
}
}
Video Store Class:
// Abhishek_22BCS80201
package project;
import java.util.Arrays;
public class VideoStore {
private Video[] store;
private int storeSize; //size of the Video store array
{
storeSize = 5;
}
public VideoStore() {
this.store = new Video[storeSize];
for (int i = 0; i < store.length; i++) {
store[i] = new Video();
}
}
public VideoStore(int storeSize) {
this.store = new Video[storeSize];
for (int i = 0; i < store.length; i++) {
store[i] = new Video();
}
}
public Video[] getStore() {
return store.clone();
}
public int getStoreSize() {
return storeSize;
}
public void setStore(Video[] store) {
this.store = store;
}
public void setStoreSize(int storeSize) {
this.storeSize = storeSize;
}
@Override
public String toString() {
return Arrays.toString(store);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
VideoStore that = (VideoStore) o;
return Arrays.equals(getStore(), that.getStore());
}
@Override
public int hashCode() {
return Arrays.hashCode(getStore());
}
public void addVideo(String name) { //allow us to add a new Video
System.out.println("\"" + name + "\" is now added to the store.");
}
public void doCheckOut(String name) { //allow a customer to rent a video
System.out.println("Thank you for renting \"" + name + "\"");
}
public void doReturn(String name) { //allows the customer to return a
video
System.out.println("Thank you for returning the \"" + name + "\"
video.");
}
public void recieveRating(String name, int rating) { //allow us to set a
new rating
System.out.println("The new rating of \"" + name + "\" is now " +
rating + " .");
}
public void listInventory() { //print all the elements of the 'store' array
for (Video video : this.store) {
System.out.println(video);
}
}
}
Output:
Experiment1.3
Student Name: Abhishek Kumar UID: 22BCS80201
Branch: BE-CSE Section/Group: CC_634-B
Semester: 6 Date of Performance: / /2024
Subject Name: Java Lab Subject Code:21CSH-319
8. Aim: Create a application to calculate interest for FDs, RDs based on certain
conditions using inheritance.
9. Objective: Develop a Java application to input user details for three account
types (SavingAccount, FixedDepositAccount, and RecurringDeposit).
Implement cases for each type to calculate interest based on specified
conditions. Ensure robust input validation and handle exceptions efficiently for
a seamless user experience.
10. A
lgo. /Approach:
Main Class (Cal_Interest_Project):
• It's a program for calculating interest on different types of accounts like
Fixed Deposit (FD), Recurring Deposit (RD), and Savings Account (SB).
• The main method of this class:
o Sets up instances for each type of account.
o Displays a menu for the user to choose the type of account they want
to calculate interest for.
• Reads user input and performs calculations accordingly.
• Allows the user to exit the program or handles invalid input.
Account Classes (FDAccount, RDAccount, SBAccount):
• Each class represents a specific type of account and includes methods to set
account details and calculate interest based on the input provided.
• This class is used to handle invalid input exceptions, such as entering
negative amounts or incorrect account types.
11. C
ode and Output:
FD Account Class:
// Abhishek kumar_22BCS80201
package project_3;
public class FDAccount extends Interest_Cal {
private int noOfDays;
private int ageACHolder;
void set(int amount, int noOfDays, int ageACHolder) {
this.amount=amount;
this.noOfDays = noOfDays;
this.ageACHolder = ageACHolder;
}
void setInterestRate(){
if (amount <= 10000000) {
if (noOfDays >= 7 && noOfDays <= 14) {
interestRate = (ageACHolder>=60) ? 0.05 : 0.045;
}
else if (noOfDays >= 15 && noOfDays <= 29) {
interestRate = (ageACHolder>=60) ? 0.0525 : 0.0475;
}
else if (noOfDays >= 30 && noOfDays <= 45) {
interestRate = (ageACHolder>=60) ? 0.06 : 0.055;
}
else if (noOfDays >= 45 && noOfDays <= 60) {
interestRate = (ageACHolder>=60) ? 0.075 : 0.07;
}
else if (noOfDays >= 61 && noOfDays <= 184) {
interestRate = (ageACHolder>=60) ? 0.08 : 0.075;
}
else{
interestRate = (ageACHolder>=60) ? 0.085: 0.08;
}
}
else {
if (noOfDays >= 7 && noOfDays <= 14) {
interestRate = 0.065;
}
else if (noOfDays >= 15 && noOfDays <= 29) {
interestRate = 0.0675;
}
else if (noOfDays >= 30 && noOfDays <= 45) {
interestRate = 0.0675;
}
else if (noOfDays >= 45 && noOfDays <= 60) {
interestRate = 0.08;
}
else if (noOfDays >= 61 && noOfDays <= 184) {
interestRate = 0.085;
}
else{
interestRate = 0.1;
}
}
}
double calculateInterest() {
setInterestRate();
return interestRate*amount;
}
}
SB Account Class:
package project_3;
public class SBAccount extends Interest_Cal{
private String ACType;
void set(String ACType,int amount) {
this.ACType=ACType;
this.amount=amount;
}
void setInterestRate() {
interestRate = (ACType.equals("NRI"))? 0.06: 0.04;
}
double calculateInterest() {
setInterestRate();
return amount*interestRate;
}
}
RD Account Class:
package project_3;
public class RDAccount extends Interest_Cal {
private int noOfMonths;
private int ageACHolder;
void set(int amount, int noOfMonths, int ageACHolder) {
this.amount=amount;
this.noOfMonths = noOfMonths;
this.ageACHolder = ageACHolder;
}
void setInterestRate() {
if(noOfMonths == 6) {
interestRate = (ageACHolder>=60)? 0.08 : 0.075;
}
else if(noOfMonths == 9) {
interestRate = (ageACHolder>=60)? 0.0825 : 0.0775;
}
else if(noOfMonths == 12) {
interestRate = (ageACHolder>=60)? 0.085 : 0.08;
}
else if(noOfMonths == 15) {
interestRate = (ageACHolder>=60)? 0.0875 : 0.0825;
}
else if(noOfMonths == 18) {
interestRate = (ageACHolder>=60)? 0.09 : 0.085;
}
else{
interestRate = (ageACHolder>=60)? 0.0925 : 0.0875;
}
}
double calculateInterest() {
setInterestRate();
return amount * interestRate;
}
}
Output: