CHANDIGARH UNIVERSITY
UNIVERSITY INSTITUTE OF ENGINEERING
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
Submitted By: Submitted To:
Abhishek Pandey Er. Amritpal Kaur
20BCS9188 (E13305)
20BCS_WM-608/A
Subject Name PBL in Java Lab
Subject Code 20CSP-321
Branch BE-CSE
Semester 5th Sem
LAB INDEX
NAME: Abhishek Pandey SUBJECT NAME: PBL in Java Lab
UID: 20BCS9188 SUBJECT CODE: 20CSP-321
SECTION: 20BCS_WM-608/A
Sr. Program Date Evaluation Sign
No LW VV FW Total
(12) (10) (8) (30)
Worksheet Experiment 1
Student Name: Abhishek Pandey UID: 20BCS9188
Branch: CSE Section/Group: WM-608/A
Semester: 5th Sem Date of Performance: 9th Aug,2022
Subject Name: PBL in Java Lab Subject Code: 20CSP-321
1. Aim/Overview of the practical:
Create an application to save the employee information using arrays.
2. Task to be done:
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 following details as output:
Algorithm:
Step 1: Start.
Step 2: Declare integer variables for basic_salary, hra, it, ta and total_salary.
Step 3: Input the department from user.
Step 4: switch(ch)
Step 4.1: case 'e':
{
designation = "Engineer";
da = 20000;
}
Step 4.2: case 'c':
{
designation = "Consultant
da = 32000;
}
Step 4.3: case 'k':
{
designation = "Clerk";
da = 12000;
}
Step 4.4: case 'R':
{
designation = "Receptonist";
da = 15000;
}
Step 4.4: case 'm':
{
designation = "Manager";
da = 40000;
}
Step 4.5: default:
Step 4.5.1: Print "Invalid".
Step 5: Stop
3. Source Code:
import [Link];
/*
*Abhishek Pandey
*Chandigarh University
*UID: 20BCS9188
*/
public class Exp_1 {
public static void main(String[] args) {
Scanner a=new Scanner([Link]);
int[] empno = {9188,5123,9168,9167,9162,9204,2167};
String[] name ={"Abhishek","Shreya","Aditya","Anant","Raj","Yashika","Rajdeep"};
char[] d_code = {'e','c','k','r','m','e','c'};
String[] dept ={"R&D","PM","Acct","front","Desk","Engg","Manufacturing","PM"};
int[] basic = {20000,30000,10000,12000,50000,23000,29000};
int[] hra = {8000,12000,8000,6000,20000,9000,12000};
int[] it = {3000,9000,1000,2000,20000,4400,10000};
String designation;
int da;
int salary;
int index = -1;
[Link]("Enter the employee_id to find ::");
int emp= [Link]();
for(int i=0;i<[Link];i++)
{
if (empno[i]==emp)
{
index=i;
}
}
if (index==-1)
{
[Link]("There is no such employee." +emp);}
else
{
char code;
code=d_code[index];
switch (code)
{
case 'e' ->
{
designation = "Engineer";
da = 20000;
}
case 'c' ->
{
designation = "Consultant
da = 32000;
}
case 'k' -> {
designation = "Clerk";
da = 12000;
}
case 'r' ->
{
designation = "Receptonist";
da = 15000;
}
case 'm' ->
{
designation = "Manager";
da = 40000;
}
default ->
{
designation = "Invalid";
da = 0;
}
}
salary=basic[index]+ hra[index]+da-it[index];
[Link]("Emp No" +" "+"Emp Name" +" "+"Department"+"
"+"Designation"+" "+"Salary");
[Link](empno[index]+" "+name[index]+" "+dept[index] +"
"+designation +" "+salary);
[Link]("Code by: Abhishek Pandey");
[Link]("UID: 20BCS9188");
}
}
}
4. Result/Output:
Learning outcomes (What I have learnt):
1. Familiar with Environment
2. Basic functions to perform on array
3. Create table using array
4. Uses of switch case
5. Classes in java
6. Function in java
Evaluation Grid:
Sr. No. Parameters Marks Obtained Maximum Marks
1. Student Performance 12
(Conduct of experiment)
objectives/Outcomes.
2. Viva Voce 10
3. Submission of Work Sheet 8
(Record)
Total 30
Worksheet Experiment 2
Student Name: Abhishek Pandey UID: 20BCS9188
Branch: CSE Section/Group: WM-608/A
Semester: 5th Sem Date of Performance: 16th Aug,2022
Subject Name: PBL in Java Lab Subject Code: 20CSP-321
1. Aim/Overview of the practical:
Design and implement a simple inventory control system for a small video rental store.
2. Task to be done:
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.
Assume that an object of class Video has the following attributes:
1.A title; 2.a flag to say whether it is checked out or not; and 3. An average user rating.
Add instance variables for each of these attributes to the Video class.
In addition, you will need to add methods corresponding to the following:
[Link] checked out; 2. being returned; and 3. receiving a rating.
The VideoStore class will contain at least an instance variable that references an array of videos
(say of length 10). The VideoStore will contain the following methods:
[Link](String): add a new video (by title) to the inventory;
[Link](String): check out a video (by title);
[Link](String): return a video to the store;
[Link](String, int) : take a user's rating for a video; and
[Link](): list the whole inventory of videos in the store.
Finally, create a VideoStoreLauncher class with a main() method which will test the functionality
of your other two classes.
3. Algorithm:
[Link].
2. make a class with name Video. In this class make variable related to video.
3. make a class with name VideoStore. In this class functions are made for add video, rent video, return video.
4. make a main class with name VideoStoreLauncher. In this class we call all the function with object of the
class.
5. End.
4. Source Code:
import [Link];
/*
*Abhishek Pandey
*Chandigarh University
*UID: 20BCS9188
*/
public class Video
{
public String title;
public boolean checked=true;
int avgrating;
public boolean checked()
{
return checked;
}
public void rent()
{
checked=false;
}
public void returned()
{
checked=true;
[Link]("Video is returned ");
}
public int getRating()
{
if(avgrating>0)
{
return avgrating;
}
else{
[Link](" Rating is not available");
return 0;
}
}
}
class VideoStore extends Video
{
Video v[]=new Video[10]; static
int i=0;
void addVideo(String title) {
v[i]=new Video();
[Link]=title;
v[i].title=title;
i++;
[Link]("Video Added Successfully");
}
void checkOut(String title) {
for(int k=0;k<i;k++) {
if(v[k].[Link](title)){
if(v[k].checked()){
v[k].rent();
[Link]("Video is rented");
} else{
[Link]("Sorry Video not available");
}
}
}
}
void returnVideo(String title){
if(i==0) {
[Link]("You have no video to return");
}
for(int k=0;k<i;k++) { if(v[k].[Link](title))
{
v[k].checked=true;
}
}
}
public void receiveRating() { if(i==0)
{
[Link]("No Video inInventory");
} else{
for(int k=0;k<i;k++) {
[Link]("Enter the rating for movie"+v[k].title);
Scanner ob=new Scanner([Link]);
v[k].avgrating=[Link]();
}
}
}
public void listInventory(){
if(i==0) {
[Link]("No Video in Inventory");
}
else {
for(int k=0;k<i;k++) {
[Link](k+1 +". "+v[k].title+" "+"Rating "+v[k].avgrating+" Availability
"+v[k].checked());
}
}
}
}
class VideoStoreLauncher {
public static void main(String[] args) {
[Link]("Code by: Abhishek Pandey");
[Link]("UID: 20BCS9188");
VideoStore vs=new VideoStore();
int ch,uCh,aCh;
String title,choice;
do {
[Link]("=========Menu=========");
[Link]("1. Login as User");
[Link]("2. Login as Admin");
[Link]("Enter Your Choice: ");
Scanner s=new Scanner([Link]);
ch=[Link]();
do {
switch(ch) {
case 1:
[Link]("1. List Inventory");
[Link]("2. Rent Video");
[Link]("3. Enter the rating of Video");
[Link]("4. Return Video");
uCh=[Link]();
if(uCh==1) {
[Link]();
}
else if(uCh==2) {
[Link]();
[Link]("Enter the video Name you want");
title=[Link]();
[Link](title);
}
else if(uCh==3){
[Link]();
}
else if(uCh==4) {
[Link]();
}
else {
[Link]("No such Option is available");
}
break;
case 2:
[Link]("1. List Inventory");
[Link]("2. Add Video");
aCh=[Link]();
if(aCh==1) {
[Link]();
}
if(aCh==2) {
[Link]("Enter the name of Video");
title=[Link]();
[Link](title);
// [Link]();
}
break;
default:[Link]("Sorry Wrong Choice");
}
[Link]("Do you want to repeat yes/no");
choice=[Link]();
} while([Link]("yes"));
[Link]("Want to Return to main Menu yes/no");
choice=[Link]();
} while([Link]("yes"));
}
}
5. Result/Output:
Learning outcomes (What I have learnt):
1. Familiar with Environment
2. Basic functions to perform on array and linked list
3. Create table using array
4. Uses of switch case
Evaluation Grid:
Sr. No. Parameters Marks Obtained Maximum Marks
1. Student Performance 12
(Conduct of experiment)
objectives/Outcomes.
2. Viva Voce 10
3. Submission of Work Sheet 8
(Record)
Total 30
Worksheet Experiment 3
Student Name: Abhishek Pandey UID: 20BCS9188
Branch: CSE Section/Group: WM-608/A
Semester: 5th Sem Date of Performance: 23rd Aug,2022
Subject Name: PBL in Java Lab Subject Code: 20CSP-321
1. Aim/Overview of the practical:
Create an application to calculate interest for FDs, RDs based on certain conditions using
inheritance.
2. Task to be done:
Calculate interest based on the type of the account and the status of the account holder.
The rates of interest changes according to the amount (greater than or less than 1 crore), age of
account holder (General or Senior citizen) and number of days if the type of account is FD or
RD.
3. Algorithm/Flowchart:
1. Make account class.
2. Using method overriding create interest calculate.
3. Create FD, Rd and SD.
4. Take input of amount and age and days for fd.
5. Take input of saving account and nri and non nri
6. For Rd take amount and month and age as input.
7. Create a launcher class .
4. Source Code:
import [Link];
/*
*Abhishek Pandey
*Chandigarh University
*UID: 20BCS9188
*/
abstract class Account {
Scanner input = new Scanner([Link]);
};
class FDAccount extends Account {
double amount, Genral, Senoir, interestRate, total;
int noOfDays;
int ageOfHolder;
double calculateintrest() {
[Link]("Enter FD Amount: ");
[Link] = [Link]();
[Link]("Enter FD number of days:
"); [Link] = [Link]();
[Link]("Enter Your Age: ");
[Link] = [Link]();
if (noOfDays < 0) {
[Link]("Invalid Days");
[Link](0);
}
if (ageOfHolder < 0) {
[Link]("Invalid age");
[Link](0);
}
if (amount < 10000000) {
if ((noOfDays >= 7) && (noOfDays <= 14)) {
Genral = 4.50;
Senoir = 5.00;
} else if ((noOfDays >= 15) && (noOfDays <= 29)) {
Genral = 4.75;
Senoir = 5.25;
} else if ((noOfDays >= 30) && (noOfDays <= 45)) {
Genral = 5.50;
Senoir = 6.00;
} else if ((noOfDays >= 46) && (noOfDays <= 60)) {
Genral = 7;
Senoir = 7.50;
} else if ((noOfDays >= 61) && (noOfDays <= 184)) {
Genral = 7.50;
Senoir = 8.00;
} else if ((noOfDays >= 185) && (noOfDays <= 365)) {
Genral = 8.00;
Senoir = 8.50;
}
interestRate = ((ageOfHolder < 50) ? Genral : Senoir);
} else {
if ((noOfDays >= 7) && (noOfDays <= 14)) {
interestRate = 6.50;
} else if ((noOfDays >= 15) && (noOfDays <= 29)) {
interestRate = 6.75;
} else if ((noOfDays >= 30) && (noOfDays <= 45)) {
interestRate = 6.75;
} else if ((noOfDays >= 46) && (noOfDays <= 60)) {
interestRate = 8;
} else if ((noOfDays >= 61) && (noOfDays <= 184)) {
interestRate = 8.50;
} else if ((noOfDays >= 185) && (noOfDays <= 365)) {
interestRate = 10.00;
}
}
total = ((amount * (interestRate) / 100));
return total;
}
}
class SBAccount extends Account {
double interestRate;
double amount;
int choice;
double calculateintrest() {
[Link]("Enter Amount: ");
[Link] = [Link]();
[Link]("[Link] account: ");
[Link]("2. Normal account: ");
choice = [Link]();
if (choice == 1) {
interestRate = 0.06;
} else if (choice == 2) {
interestRate = 0.04;
} else if (choice < 0 || choice > 2) {
[Link]("Worng Input ! ");
[Link](0);
}
return amount * interestRate;
}
}
class RDAccount extends Account {
double interestRate, amount, Genral, Senoir, total;
int noofMonths;
int ageOfHolder;
double calculateintrest() {
[Link]("Enter RD Amount: ");
[Link] = [Link]();
[Link]("Enter RD Months: ");
[Link] = [Link]();
[Link]("Enter Your Age: ");
[Link] = [Link]();
if (noofMonths < 0) {
[Link]("Invalid Months");
return 0;
}
if (ageOfHolder < 0) {
[Link]("Invalid age");
return 0;
}
if (noofMonths <= 6) {
Genral = 7.50;
Senoir = 8.00;
} else if (noofMonths <= 9) {
Genral = 7.55;
Senoir = 8.25;
} else if (noofMonths <= 12) {
Genral = 8.00;
Senoir = 8.50;
} else if (noofMonths <= 15) {
Genral = 8.25;
Senoir = 8.75;
} else if (noofMonths < 18) {
Genral = 8.50;
Senoir = 9.00;
} else if (noofMonths < 21) {
Genral = 8.75;
Senoir = 9.25;
}
interestRate = ((ageOfHolder < 50) ? Genral : Senoir);
total = ((amount * (interestRate) / 100));
return total;
}
}
public class InterestCalculator {
public static void main(String[] args) {
[Link]("Code by: Abhishek Pandey");
[Link]("UID: 20BCS9188");
try (Scanner input = new Scanner([Link])) {
[Link]("Select the option: ");
[Link]("1. Interest Calculator SB: ");
[Link]("2. Interest Calculator FD: ");
[Link]("3. Interest Calculator RD: ");
[Link]("4. Exit");
int choice;
choice = [Link]();
switch (choice) {
case 1:
SBAccount sb = new SBAccount();
[Link]([Link]());
break;
case 2:
FDAccount fb = new FDAccount();
[Link]([Link]());
break;
case 3:
RDAccount rd = new RDAccount();
[Link]();
break;
case 4:
[Link](0);
break;
}
}
}
}
5. Result/Output:
Learning outcomes (What I have learnt):
1. Familiar with Environment
2. Basic functions to perform on array and linked list
3. Uses of abstract class and inheritance
4. Uses of switch case
Evaluation Grid:
Sr. No. Parameters Marks Obtained Maximum Marks
1. Student Performance 12
(Conduct of experiment)
objectives/Outcomes.
2. Viva Voce 10
3. Submission of Work Sheet 8
(Record)
Total 30