Programming Placement Question

Programming Placement Question

Share

Learn and practice Programming questions and answers with explanation for interview , competitive examination and entrance test.

31/12/2020

"Wishing every day of the New Year to be filled with success, happiness, and prosperity for you. Happy New Year 2021!" ЁЯЩВтЬМя╕П я╗┐, ,

31/10/2019

Project on Collections Framework
Using Collection object as Mini DataBase
================================
In this project we have used complete Core Java concepts.
In this project we have used
1) OOP concepts
2) String Handling
3) Exception Handling with Java 7 new features
4) Collections Framework
5) IO Streams for reading Data from file
6) Serialization and Deserialization
7) Packages as per project standards

In the next version, we will enhance this project using Java 8 Stream API and Java 9 Module System .

In final version we will enhance it to web projects by using
1) HTML, Java Script, CSS, Angular
2) Adv Java (Servlet, JSP, JDBC)

I have attached required images on Project architecture and other details

Here is the code:

//=====DeptMap.java=====
package com.nit.hk.emis.util;
import java.util.HashMap;
public class DeptMap {
private static final HashMap depts;

static {
depts = new HashMap();

depts.put("CRT", 1);
depts.put("C", 2);
depts.put("DS", 3);
depts.put("CJ", 4);
depts.put("OR", 5);
depts.put("HJ", 6);
depts.put("AJ", 7);
depts.put("Spr", 8);
depts.put("Hib", 9);
depts.put("XW", 10);
}
public static int getDeptNum(String dept) {
return depts.get(dept.toUpperCase());
}
}

//=====Employee.java=====
package com.nit.hk.emis.pojo;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Serializable;

import com.nit.hk.emis.util.DeptMap;

public class Employee
implements Comparable,
Serializable{

private static final long serialVersionUID = 1L;

private static String company;

private int eno;
private String ename;
private double sal;
private String dept;

private transient long mobile;
private transient String email;
private transient double totalSal;

static { //initializing company variable
//by reading value from a file
try(
BufferedReader reader =
new BufferedReader(
new FileReader("company.txt"))
){
company = reader.readLine();

}catch(FileNotFoundException e) {
System.out.println(
"The file \"company.txt\" is not found");
System.exit(0);
}catch(IOException e) {
e.printStackTrace();
}
}

private static int count = 0;

{
count++;
}

public Employee() { }

public static String getCompany() {
return company;
}

public static void setCompany(String company) {
Employee.company = company;
}

public int getEno() {
return eno;
}

public void setEno(int eno) {
this.eno = eno;
}

public String getEname() {
return ename;
}

public void setEname(String ename) {
this.ename = ename;
}

public double getSal() {
return sal;
}

public void setSal(double sal) {
this.sal = sal;
}

public String getDept() {
return dept;
}

public void setDept(String dept) {
this.dept = dept;
}

public long getMobile() {
return mobile;
}

public void setMobile(long mobile) {
this.mobile = mobile;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public double getTotalSal() {
return totalSal;
}

public void setTotalSal(double totalSal) {
this.totalSal = totalSal;
}

public static int getCount() {
return count;
}


public int hashCode() {
return DeptMap.getDeptNum(dept);
}


public boolean equals(Object obj) {
try {
Employee e =(Employee)obj;
return this.dept.equals(e.dept)
&& this.eno == e.eno;
}catch(ClassCastException | NullPointerException e){
return false;
}
}


public int compareTo(Employee e) {
int deptDiff = this.dept.compareTo(e.dept);
if(deptDiff == 0)
return this.eno - e.eno;
return deptDiff;
}


public String toString() {
return "Employee("
+eno+", "+ename+", "
+dept+", "+sal+", "
+mobile+", "+email+")";
}
}

//==DeptNotFoundException.java==
package com.nit.hk.emis.exceptions;
public class DeptNotFoundException extends Exception {
public DeptNotFoundException() {

}
public DeptNotFoundException(String errMsg) {
super(errMsg);
}

}

//==EmployeeNotFoundException.java==
package com.nit.hk.emis.exceptions;
public class EmployeeNotFoundException extends Exception {
public EmployeeNotFoundException() {
}
public EmployeeNotFoundException(String errMsg) {
super(errMsg);
}

}

//===EmpPersist.java===
package com.nit.hk.emis.dao;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import com.nit.hk.emis.exceptions.DeptNotFoundException;
import com.nit.hk.emis.exceptions.EmployeeNotFoundException;
import com.nit.hk.emis.pojo.Employee;

public class EmpPersist {
private List empList;

("unchecked")
public EmpPersist(){
try(
ObjectInputStream ois =
new ObjectInputStream(
new FileInputStream("employees.ser"));
){
empList = (ArrayList)ois.readObject();
}catch(IOException e) {
empList = new ArrayList();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}

public void persist() {
try(
ObjectOutputStream oos =
new ObjectOutputStream(
new FileOutputStream("employee.ser"));
){
oos.writeObject(empList);

} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

public void store(Employee e) {
empList.add(e);
}

public Employee getEmployee(Employee searchEmp) {
int index = empList.indexOf(searchEmp);

if(index != -1) {
return empList.get(index);
}
return null;

}

public List getEmployeesByDept(String dept) {
List empListByDept =
new ArrayList();

for(Employee emp : empList) {
if(emp.getDept().equalsIgnoreCase(dept)) {
empListByDept.add(emp);
}
}

return empListByDept;
}

public List getEmployees() {
return List.copyOf(empList);
}

public void updateEmployee()
throws EmployeeNotFoundException{

Scanner scn = new Scanner(System.in);

Employee searchEmp = new Employee();
System.out.println(
"Enter employee details for searching");

System.out.print(" Enter eno: ");
searchEmp.setEno(scn.nextInt()); scn.nextLine();

System.out.print(" Enter dept: ");
searchEmp.setDept(scn.nextLine());

Employee emp = this.getEmployee(searchEmp);

if(emp != null) {
System.out.println("\nEnter new values to update");

System.out.println("Do you want to update ename? (Y/N): ");
if(scn.nextLine().equalsIgnoreCase("Y")) {
System.out.println(" Enter new name: ");
emp.setEname(scn.nextLine());
}

System.out.println("Do you want to update sal? (Y/N): ");
if(scn.nextLine().equalsIgnoreCase("Y")) {
System.out.println(" Enter new sal: ");
emp.setSal(scn.nextDouble()); scn.nextLine();
}

System.out.println("Do you want to update dept? (Y/N): ");
if(scn.nextLine().equalsIgnoreCase("Y")) {
System.out.println(" Enter new dept: ");
emp.setDept(scn.nextLine());
}

System.out.println("Do you want to update mobile? (Y/N): ");
if(scn.nextLine().equalsIgnoreCase("Y")) {
System.out.println(" Enter new mobile: ");
emp.setMobile(scn.nextLong()); scn.nextLine();
}

System.out.println("Do you want to update email? (Y/N): ");
if(scn.nextLine().equalsIgnoreCase("Y")) {
System.out.println(" Enter new email: ");
emp.setEmail(scn.nextLine());
}

}else {
throw new EmployeeNotFoundException(
"\nWith the given details "
+ "Employee is not found");
}

}

public void updateSalByDept(String dept, double salIncreaseBy)
throws DeptNotFoundException{
boolean updated = false;

for(Employee emp : empList) {
if(emp.getDept().equalsIgnoreCase(dept)) {
emp.setSal( emp.getSal() + salIncreaseBy );
updated = true;
}
}

if(!updated) {
throw new DeptNotFoundException(
"Department "+dept+" is not found");
}
}

public void updateAllEmpsSal(double salIncreaseBy)
throws EmployeeNotFoundException{
if(!empList.isEmpty()) {
for(Employee emp : empList) {
emp.setSal( emp.getSal() + salIncreaseBy );
}
}else {
throw new EmployeeNotFoundException("No employee found");
}
}

public boolean deleteEmployee(Employee emp) {
return empList.remove(emp);
}

public void deleteAllEmps(){
empList.clear();
}

public void display() {
if(empList.isEmpty()) {
System.out.println("No employee found");
}else {
for(Employee emp : empList) {
System.out.println(emp);
}
}
}

public void deleteEmployeesByDept(String dept)
throws DeptNotFoundException{

boolean deleted = false;
Employee emp;
for(int i=0; i

e.pr

Photos 06/10/2019

рдЗрд╕ рджреБрд░реНрдЧрд╛ рдкреВрдЬрд╛ рдкрд░ рдорд╛рдБ рджреБрд░реНрдЧрд╛ рдЖрдкрдХреЛ рд╢рд╛рдВрддрд┐, рд╕рдореНрдкрддрд┐ рдФрд░ рд╢рдХреНрддрд┐ рджреЗред рджреБрд░реНрдЧрд╛ рдкреВрдЬрд╛ рдХреА рд╢реБрднрдХрд╛рдордирд╛рдПрдВредЁЯЩПЁЯЩПЁЯСП

11/11/2018

Super () ex*****on

11/11/2018

Program EX*****ON

11/11/2018

I want to throw checked Exception from sub class even though super class didn't throw any kind of exception ..
Is it possible ?

11/11/2018

What is the contract between hascode() and equal () method?

Mobile uploads 12/09/2018

Like & Share Plz!


'18
Artwork No. : 23
Name- Manasa Manu
College- Sridevi Women's engineering college, Gandipet, Hyderabad.
Caption- "Mother's love is peace. It need not be acquired, It need not be deserved".

06/07/2017

Success and obstacles :::
It's quite obvious that you will feel low or sad at many a times in your life . But remember to keep moving and don't stop . Your today will be having its impact on your tomorrow . Results take time but when it comes then your time changes .
For your one success you need to really work hard. Bigger your goal , bigger will be stress and larger will be your struggle . But you have to move on and you need not worry . It's your patience and continuity that will matter the most . So don't feel low or sad , instead take that as a challenge and work upon it . Dream should not just be your thought but must be an action oriented towards the thought .

06/07/2017

abstract class X
{
int i = 11;
int methodOneOfX()
{
return i *= i /= i;
}
abstract void methodTwoOfX(int i);
}
class Y extends X
{

void methodTwoOfX(int i)
{
System.out.println(i);
}
}
public class Test
{
public static void main(String[] args)
{
new Y().methodTwoOfX(new Y().methodOneOfX());
}
}

06/07/2017

How to change the heap size of a JVM?

06/07/2017

i have one requirement
..................................
suppose we have 20,000 employee pojo in the form of List, i need to find duplicate employee on the based of name with a single loop
note:- use only one loop and find how many employees are duplicated

Want your school to be the top-listed School/college in Siwan?

Click here to claim your Sponsored Listing.

Location

Category

Website

Address

Siwan