Thursday, January 21, 2010

IT123_PRELABEXERCISES

package entity;

public class Employee {

private int id;
private String name;
private int age;
private double salary;
private Department department;

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

public Department getDepartment() {
return department;
}

public void setDepartment(Department department) {
this.department = department;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public double getSalary() {
return salary;
}

public void setSalary(double salary) {
this.salary = salary;
}

public Employee(int id, String name, int age, double salary, Department department) {
this.id = id;
this.name = name;
this.age = age;
this.salary = salary;
this.department = department;
}

public Employee() {
}



public String displayEmployeeInfo() {
return "\nName:" + name + "\nAge:" + age + "\nID:" + id + "Department:" + department;


}
}

package entity;


public class Department {

private String description;
private int deptId;

public int getDeptId() {
return deptId;
}

public void setDeptId(int deptId) {
this.deptId = deptId;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public Department(int deptId,String description) {

this.deptId = deptId;
this.description = description;
}

public Department() {
}

public void displayInfo(){
System.out.println("Department Info." + description + "," + deptId + ",");

}

}



package demo;

import entity.*;
import java.util.Stack;

public class StackTest {

public static void main(String[] args){

Stackannie=new Stack();

annie.push(new Employee(100, "Jhon Smith", 23, 19304.54, new Department(11, "Marketing")));
annie.push(new Employee(101, "Eric Page", 25, 39304.54, new Department(12, "Resarch Development")));
annie.push(new Employee(102, "Caroline Santos", 28, 1904.54, new Department(13, "Human Resource")));

System.out.println("Stack size" +annie.size());
System.out.println("");
System.out.println();
System.out.println("Stack peek\n" +annie.peek().displayEmployeeInfo());
System.out.println("");
System.out.println("Performing pop operations..");
System.out.println("");

while (!annie.empty()){
Employee e = annie.pop();
System.out.println(e.displayEmployeeInfo());
System.out.println(".....................");
}

if (annie.empty()){
System.out.println("Stack is empty....");
}


}

}
\*THIS IS A RUNNABLE PROGRAM\
########################################################################################

package entity;


public class LinearSearch {

public static void main(String[] args) {

int[] a = {5, 10, 8, 6, 3, 10};
int searchKey = 6;
String x;
for (int i = 0; i <= a.length - 1; i++) {
if (searchKey == a[i]) {
x = "I found it!Yehey!!";


} else {
x = "Sorry I did not found it!";
}

System.out.println(x);
}
}
}


\*THIS A RUNNABLE PROGRAM\*
#########################################################################################


package entity;

public class LinerRunime {

public static void min(String[] args){

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



int searchKey=5;
String x="";
for(int i=0; i<=a.length-1; i++){
if(searchKey==a[1]){
x="EXIST";
break;
}
else{
x="NOT EXIST";
}
}
System.out.println(x);
}
}
\*THIS A RUNNABLE PROGRAM\*
##########################################################################################


package entity;

import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;


public class PrintIntegerArraySort {

public static void main(String[] args) {

int[] integers = {10, 9, 0, 1, 11, 2, 5, 4};

ArrayList listInt = new ArrayList();



listInt.add(1);
listInt.add(10);
listInt.add(5);


System.out.println("COLLECTION SORT");
Collections.sort(listInt);
for (int a : listInt) {
System.out.println(a);
}
System.out.println("REVERSE COLLECTIONS");
Collections.reverse(listInt);
for (int j : listInt) {
System.out.println(j);

}

System.out.println("ARRAY SORT");
Arrays.sort(integers);

for (int i : integers) {

System.out.println(i);



}

}
}
\*THIS A RUNNABLE PROGRAM\*
##########################################################################################

package entity;

import java.util.*;
import java.util.ArrayList;


public class Untypedata {

public static Scanner console = new Scanner(System.in);

public static void main(String[] args) {



ArrayList unlist = new ArrayList();




int annie=5;

while (annie != 0) {

System.out.println("Enter double data");
double lhen = console.nextDouble();

annie--;


}

System.out.println("");

System.out.println("SORT DOUBLE TYPE");
for (double i : unlist) {

System.out.println(i);


}
}
}

\*THIS A RUNNABLE PROGRAM\*
##########################################################################################


package demo;

public class Constantruntime {

public static void min(String[] args){


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


int searchKey=5;
String x="";
for(int i=0; i<=a.length-1; i++){
if(searchKey==a[1]){
x="They are not equal!";
break;
}
else{
x="They are equal!";
}
}
System.out.println(x);
}
}
\*THIS A RUNNABLE PROGRAM\*
##########################################################################################

No comments:

Post a Comment