Back-End-Assignements
Back-End-Assignements
Answer-
package com.question1.oops_concept;
class Movie
String title;
String director;
int duration;
// b) Class constructor
title = t;
director = d;
duration = dur;
// c) Method overloading
void displayInfo()
if (showDuration)
String animationStudio;
super(t, d, dur);
animationStudio = studio;
// Method overriding
void displayInfo()
super.displayInfo();
// f) Interface
interface MovieOperations
void watchMovie();
// g) Abstract class
String name;
Viewer(String n)
name = n;
int favoriteMovieId;
super(n);
favoriteMovieId = favId;
void displayViewerInfo()
System.out.println(name + " rated the movie " + rating + " out of 5.");
// Creating objects
// Method overloading
movie1.displayInfo();
movie1.displayInfo(false);
// Method overriding
animatedMovie1.displayInfo();
fan.displayViewerInfo();
fan.watchMovie();
fan.rateMovie(5);
Output 1-
2. Design a Java program that performs various string operations and uses control
statements for user input validation. The program should allow the user to perform the
following operations:
a) Extract Substring: The user can enter a string and specify the starting and ending
index, and the program should extract and display the substring.
b) Split a Sentence: The user can enter a sentence, and the program should split it
into words and display them.
Answer-
package com.question2.string_Concept;
import java.util.Scanner;
while (true) {
// Display menu
System.out.println("Choose an operation:");
System.out.println("3. Exit");
switch (choice) {
case 1:
// Extract Substring
if (startIndex >= 0 && endIndex <= inputString.length() && startIndex < endIndex) {
} else {
break;
case 2:
// Split a Sentence
System.out.println(word);
break;
case 3:
// Exit
System.exit(0);
default:
} } } }
OUTPUT 2 –
1) 3. Design a Java program to implement a Collection Management System that manages
different types of collections such as lists, sets, and maps. The program should allow users
to perform the following operations for each type of collection:
a) Lists:
i) Add an element: The user can add an element to the list.
ii) Remove an element: The user can remove an element from the list.
iii) Display all elements: The user can view all elements in the list.
b) Sets:
i) Add an element: The user can add an element to the set.
ii) Remove an element: The user can remove an element from the set.
iii) Display all elements: The user can view all elements in the set.
iv) Implement exception handling to handle possible errors (e.g., element not
found in the list/set, duplicate keys in the map).
v) Provide a user-friendly console interface for the user to interact with the
Collection Management System.
Answer –
package com.question3.collectionmanagementsystem;
import java.util.*;
while (true)
System.out.println("1. List");
System.out.println("2. Set");
System.out.println("3. Map");
System.out.println("4. Exit");
scanner.nextLine();
switch (choice)
case 1:
performListOperations(scanner);
break;
case 2:
performSetOperations(scanner);
break;
case 3:
performMapOperations(scanner);
break;
case 4:
System.out.println("Exiting...");
System.exit(0);
default:
{
System.out.println("List Operations:");
scanner.nextLine();
if (listChoice == 1)
list.add(listElementToAdd);
else if (listChoice == 2)
if (list.remove(listElementToRemove))
else
else if (listChoice == 3)
{
System.out.println("List Elements:");
System.out.println(item);
else
System.out.println("Set Operations:");
if (setChoice == 1)
if (set.add(setElementToAdd))
{
System.out.println("Element added to the set.");
else
else if (setChoice == 2)
if (set.remove(setElementToRemove))
else
else if (setChoice == 3)
System.out.println("Set Elements:");
System.out.println(item);
else
System.out.println("Map Operations:");
if (mapChoice == 1)
map.put(mapKey, mapValue);
else if (mapChoice == 2)
if (map.remove(mapKey) != null)
{
else
else if (mapChoice == 3)
else if (mapChoice == 4)
if (value != null)
else
else if (mapChoice == 5)
{
if (map.containsKey(mapKey))
else
else if (mapChoice == 6)
map.clear();
System.out.println("Map cleared.");
else if (mapChoice == 7)
else
} }}
OUTPUT 3 –
List Operation
SET Operations –
Map Operations
2) 4. Add new employees: The user can add details like employee ID, name, department, and
salary.
a) Update employee details: The user can update the name, department, or salary of
an existing employee based on their employee ID.
b) Delete an employee: The user can delete an employee from the system based on
their employee ID.
c) Display all employees: The user can view a list of all employees and their details.
d) Search for an employee: The user can search for an employee by their employee ID
and view their details.
e) Requirements:
ii) Use appropriate data structures (e.g., ArrayList, HashMap) to store the
employee data.
iv) Provide a user-friendly console interface for the user to interact with the
Employee Management System.
Answer –
package com.question4.employeemanagementsystem;
this.id = id;
this.name = name;
this.department = department;
this.salary = salary;
this.id = id;
return name;
this.name = name;
return department;
this.department = department;
return salary;
this.salary = salary;
@Override
return "Employee ID: " + id + ", Name: " + name + ", Department: " + department + ", Salary: " +
salary;
}
EmployeeManagementSystem.java --
package com.question4.employeemanagementsystem;
import java.util.HashMap;
import java.util.Scanner;
public EmployeeManagementSystem() {
int id = scanner.nextInt();
employeeMap.put(id, employee);
}
// Method to update an existing employee
int id = scanner.nextInt();
if (employeeMap.containsKey(id)) {
if (!name.isEmpty()) {
employee.setName(name);
if (!department.isEmpty()) {
employee.setDepartment(department);
if (salary != -1) {
employee.setSalary(salary);
employeeMap.put(id, employee);
} else {
}
// Method to delete an employee
int id = scanner.nextInt();
if (employeeMap.remove(id) != null) {
} else {
if (employeeMap.isEmpty()) {
} else {
System.out.println(employee);
int id = scanner.nextInt();
if (employee != null) {
System.out.println(employee);
} else {
while (true) {
System.out.println("6. Exit");
switch (choice) {
case 1:
addEmployee();
break;
case 2:
updateEmployee();
break;
case 3:
deleteEmployee();
break;
case 4:
displayAllEmployees();
break;
case 5:
searchEmployee();
break;
case 6:
System.out.println("Exiting...");
scanner.close();
return;
default:
system.run();
OUTPUT –
5. Design a Java program to create a simple employee management system using JDBC and MySQL
Connector/J. The program should allow users to perform the following operations:
a) Add a new employee: The user can enter details like employee ID, name, department, and
salary, and the program should add the employee to the database.
b) Update employee details: The user can update the name, department, or salary of an existing
employee based on their employee ID.
c) Delete an employee: The user can delete an employee from the database based on their
employee ID.
d) Display all employees: The program should retrieve and display a list of all employees and their
details from the database.
e) Requirements:
i) Use JDBC and MySQL Connector/J to connect to the MySQL database and perform CRUD
(Create, Read, Update, Delete) operations.
ii) Implement exception handling to handle possible errors during database interactions.
iii) Provide a user-friendly console interface for the user to interact with the employee
management system.
iv) f) Cover Java topics such as classes, methods, user input and output (I/O), and exception
handling. Note: Before running the program, make sure you have MySQL installed, create a
database named "employee_management," and a table named "employees" with columns: "id"
(INT, PRIMARY KEY), "name" (VARCHAR), "department" (VARCHAR), and "salary" (DOUBLE)
Answer-
package com.question5.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;
try {
while (true) {
System.out.println("5. Exit");
scanner.nextLine();
if (choice == 1) {
int id = scanner.nextInt();
scanner.nextLine();
String query = "INSERT INTO employees (id, name, department, salary) VALUES
(?, ?, ?, ?)";
preparedStatement.setInt(1, id);
preparedStatement.setString(2, name);
preparedStatement.setString(3, department);
preparedStatement.setDouble(4, salary);
preparedStatement.executeUpdate();
else if (choice == 2) {
int id = scanner.nextInt();
preparedStatement.setString(1, name);
preparedStatement.setString(2, department);
preparedStatement.setDouble(3, salary);
preparedStatement.setInt(4, id);
if (rowsUpdated > 0) {
} else {
else if (choice == 3) {
// Delete an employee
int id = scanner.nextInt();
if (rowsDeleted > 0) {
else {
} }
else if (choice == 4) {
System.out.println("\nEmployee Details:");
while (resultSet.next())
int id = resultSet.getInt("id");
} }
else if (choice == 5) {
break;
else {
// Handle invalid choice
} }
connection.close();
} catch (SQLException e) {
OUTPUT –
7.Question
i. Write a query to display ename and job for all the employee with their half term salary
ii. Write a query to display all the details of the employees along with an annual bonus of 2000
iv. Write a query to display ename and salary with deduction of 25%."
8.Question
i. Write a query to display name and hire date of the employees if the employees were hired
during 1982 .
ii. Write a query to display name of the employee who gets salary as well as commission .
iii. Write a query to display name of the employee of employee has character 'A' as the second
character in the name.
9.Question
i. Write a query to display avg salary needed to pay all the employees in each department
excluding the employees of deptno 20.
ii. Write a query to display number of employees having character 'a' in their names in each job .
iii. Write a query to display maximum salaries given to an employee working in each dept
iv. Write a query to display ename and job of all the employees working in the same designation as
james.
v. Write a query to display ename and hiredate of the employees who's name end’s with 's' and
hired after james .
create table dept
primary key(Deptno));
create table
Emp (
HIREDATE DATE ,
MGR INT(20),
SAL INT(10),
COMM INT(20),
DEPTNO INT(3),
PRIMARY KEY(EMPNO),
select*from dept;
VALUES
INSERT INTO emp (EMPNO, ENAME, JOB, HIREDATE, MGR, SAL, COMM, DEPTNO)
VALUES
-- 7.Question
-- i. Write a query to display ename and job for all the employee with their half term salary.
FROM employees;
-- of 2000.
FROM emp;
-- a hike of 10%.
SELECT ENAME, SAL, SAL * 1.1 AS SALARY_WITH_HIKE
FROM emp;
FROM emp;
-- 8. question-
FROM emp
-- Write a query to display name of the employee who gets salary as well
-- as commission .
SELECT ENAME
FROM emp
SELECT ENAME
FROM emp
FROM emp
GROUP BY DEPTNO;
-- each job
FROM emp
GROUP BY JOB;
FROM emp
GROUP BY DEPTNO;
FROM emp
-- Write a query to display ename and hiredate of the employees who's name end’s with 's' and
hired after james
FROM emp
AND HIREDATE > (SELECT HIREDATE FROM emp WHERE ENAME = 'JAMES');
OUTPUT-
7 .i)
7 .ii)
7.iii)
7.iv)
8.i)
8.ii)
8.iii)
8.iv)
9.i)
9.ii)
9.iii)
9.iv)
9.v)