0% found this document useful (0 votes)
16 views7 pages

Java Program: Public Class Employee (Int Eid String Ename

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views7 pages

Java Program: Public Class Employee (Int Eid String Ename

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Write a java code implementing collections, to generate a unique

OTP number based on the user request. The code prompts the
user to input user id and time in sec. If the request is within 60sec
the code should generate same OTP. If the request is after 60sec a
new OTP has to be generated.

Create a class that maintains a list of user id and name. Create


another class which accepts the user request, user id and time.

1<n<20 – Number of inputs

1<ID<10 – User Id

1<t<200 – Time in seconds

OUTPUT

USER ID NAME OTP

3 Jay 658

1 RAJ 567

Real-time examples of using ArrayList in java


Q. Write a java program that contains an Employee class with the following properties. eid (type is
int), ename (type is String), Department (type is Department). Now create another class named
Department which contains the properties did(type is int), dname(type is String) and designation (type
is String). Now create another class named EmployeeApp which contains the main method.

Now write code that prompts the user to enter the Employee details like id, name, and prompt
Department details like department id, name and designation details in ArrayList<Employee>
object. Enter at least 3 employees and department info print those details to the output by iterating
through Department ArrayList. Another important thing is that the property Department in Employee
class should be of type Department (which is a class).

First class ‘Employee’:

public class Employee {

int eid;
String ename;
Department department;

public Employee(int eid, String ename, Department department) {

this.eid = eid;
this.ename = ename;
this.department = department;
}
}

Second class ‘Department’:

public class Department {

int did;
String dname;
String designation;

public Department(int did, String dname, String designation) {

this.did = did;
this.dname = dname;
this.designation = designation;
}
}

Final Class ‘EmployeeApp’:

import java.util.ArrayList;
import java.util.Scanner;

public class EmployeeApp {

static ArrayList<Employee> list = new ArrayList<Employee>();

static void pushElement(Employee obj) {


list.add(obj);
}

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.println("How many Employee's information to be


stored?");
int count = sc.nextInt();

for (int i = 0; i <= count; i++) {


System.out.println("Enter Employee ID: ");
int eid = sc.nextInt();

System.out.println("Enter Employee Name: ");


String ename = sc.next();

System.out.println("Enter Department ID: ");


int did = sc.nextInt();

System.out.println("Enter Department Name");


String dname = sc.next();

System.out.println("Enter Department designation: ");


String designation = sc.next();

Department d = new Department(did, dname, designation);


Employee eobj = new Employee(eid, ename, d);
pushElement(eobj);
}

System.out.println("--- Employee Information ---");

for (Employee obj : list) {


System.out.println("Employee ID: " + obj.eid);
System.out.println("Employee Name: " + obj.ename);
Department department = obj.department;
System.out.println("Department ID: " +
obj.department.did);
System.out.println("Department Name :" +
obj.department.dname);
System.out.println("Department designation " +
obj.department.designation);
}
}
}

1D Array

import java.util.*;

public class Solution {

public static boolean canWin(int leap, int[] game, int i) {

if (i < 0 || game[i] == 1)

return false;

if (i + 1 >= game.length || i + leap >= game.length)

return true;

game[i] = 1;

return canWin(leap, game, i + leap)

|| canWin(leap, game, i + 1)

|| canWin(leap, game, i - 1);

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

int q = scan.nextInt();
while (q-- > 0) {

int n = scan.nextInt();

int leap = scan.nextInt();

int[] game = new int[n];

for (int i = 0; i < n; i++) {

game[i] = scan.nextInt();

System.out.println( (canWin(leap, game,0)) ? "YES" : "NO" );

scan.close();

Overloading Main Method


public class Helloworld {

public static void main(String[] args) {


System.out.println("Inside main(String[] args) method ....");

public static void main(Integer[] args){


System.out.println("Inside main(Integer[] args) method ....");
}

public static void main(Double[] args){


System.out.println("Inside main(Double[] args) method ....");
}

Read more: http://www.java67.com/2015/06/can-you-overload-or-override-main-in-


java.html#ixzz5ezgJxPwr

Employee details program


public class HelloWorld{
public static void main(String []args){

String arr[]={"1005"};

int DA=0,Basic=0,HRA=0,IT=0;

String desig="",Name="",dept="";

String ch="";

// String employeeDetails[][]=new String[10][8];

String salaryDetails[][]={{"e","Engineer","20000"},

{"c","Consultant","32000"},

{"k","Clerk","12000"},

{"r","Reception","15000"},

{"m","manager","40000"}

};

String employeeDetails[][]= {{"1001", "Rajan", "01/04/2019", "e", "RandD", "28000",


"8000", "3000"},

{"1002", "Sushma", "23/08/2012", "c", "Program Manager", "30000", "12000", "900"},

{"1003", "Rahul", "11/11/2008", "k", "Accountant", "10000", "800", "100"},

{"1004", "Chandru", "19/01/2013", "r", "Front office", "12000", "6000", "2000"},

{"1005", "Ranjan", "29/01/2013", "m", "Engineer", "50000", "2000", "2500"},

{"1006", "Suman", "16/07/2005", "e", "Manager", "23000", "8500", "4400"},

{"1007", "Roshini", "12/06/2006", "c", "Program Manager", "29000", "12000", "1000"}

};

for(int i=0;i<6;i++)

if (arr[0]==employeeDetails[i][0])

Name = employeeDetails[i][1];

ch= employeeDetails[i][3];

dept= employeeDetails[i][4];

Basic=Integer.parseInt(employeeDetails[i][5]);

HRA=Integer.parseInt(employeeDetails[i][6]);
IT=Integer.parseInt(employeeDetails[i][7]);

switch(ch)

case "e": desig = salaryDetails[0][1];

DA = Integer.parseInt(salaryDetails[0][2]);

// System.out.println(desig+DA);

break;

case "c": desig = salaryDetails[1][1];

DA = Integer.parseInt(salaryDetails[1][2]);

// System.out.println(desig+DA);

break;

case "k": desig = salaryDetails[2][1];

DA = Integer.parseInt(salaryDetails[2][2]);

// System.out.println(desig+DA);

break;

case "r": desig = salaryDetails[3][1];

DA = Integer.parseInt(salaryDetails[3][2]);

// System.out.println(desig+DA);

break;

case "m": desig = salaryDetails[4][1];

DA = Integer.parseInt(salaryDetails[4][2]);

// System.out.println(desig+DA);

break;

int Salary=Basic+HRA+DA-IT;

System.out.println(arr[0]+" "+Name+" "+dept+" "+desig+" "+Salary);


}

Program to print matrix and greatest without sorting

public class matrixSort

static int count=0;

public static void main(String args[])

int arr[]={5,3,6,7,8,10,2,4,1};

int great=0;

for (int i=0; i<3; i++)

for (int j=0; j<3; j++)

System.out.print(arr[count]+" ");

if(arr[count]>great)

great=arr[count];

count++;

System.out.println();

System.out.println("Greatest number in th array is :"+great);

You might also like