nikesh

Ads

 
 
 

Share on Google+Share on Google+

patel nikesh
nikesh
1 Answer(s)      5 years and 5 months ago
Posted in : JavaScript Questions

write a java program to arange 10 employee names in ascending order.

Ads
View Answers

December 23, 2011 at 3:17 PM


import java.util.*;

class Employee{
public int salary;
public String name;
public String address;
public static int count = 0;
public Employee(){}
public Employee(String name,String address,int salary) {
super();
this.name = name;
this.address=address;
this.salary = salary;
count++;
}

public String getName(){
return name;
}
public String getAddress() {
return address;
}
public int getSalary(){
return salary;
}
}
class NameComparator implements Comparator{

    public int compare(Object emp1, Object emp2){    

        String emp1Name = ((Employee)emp1).getName();        
        String emp2Name = ((Employee)emp2).getName();
        return emp1Name.compareTo(emp2Name);
       }
 }
public class EmployeeNameInAscendingOrder{
public static void main(String[] args) throws Exception{
List<Employee> list = new ArrayList<Employee>();
list.add(new Employee("Victor","Delhi",10000));
list.add(new Employee("Jennie","Mumbai",20000));
list.add(new Employee("John","Chennai",15000));
list.add(new Employee("Daniel","Kolkata",12000));
list.add(new Employee("Angelina","Pune",16000));
list.add(new Employee("Maria","Hyderabad",22000));
list.add(new Employee("Zenn","Agra",25000));
list.add(new Employee("Andy","Jaipur",22000));
list.add(new Employee("George","Nagpur",25000));
list.add(new Employee("Chris","Darjeeling",22000));

System.out.println(" ");
int count=0;
int salary=0;
               Collections.sort(list,new NameComparator());
                for(Employee data: list){
                System.out.println(data.getName()+"\t"+data.getAddress()+"\t"+data.getSalary());
                } 

   }
}

Ads









Related Tutorials/Questions & Answers:
Tutorials   
Java Spring Hibernate Struts Training code for programming How can I dynamically load user-entered data as content of jquery dialog? java webcam integration question java coding Fix Scrollbar position in a checkboxList after postback Information Save Alert Country wise redirection to files Interface in javascript connect database with javascript Zip Code ZipCode how to validate the email login How to play FLV video files on Ipad using HTML code or javascript code? Nitobi Grid is not working in IE10/IE11 jquery issue plese help RegEx Tree structure from json whose parents can be dragged and dropped from child newyorklife insurance getElementById not working javascript code for search in html file Implement The Skeleton Code Implement This Skeleton Code Mobile Automation using Appium Computer forensic application Java: Searching a string from doc files java linked list urgent !!! java linked list urgent!!! library management library management library management library management question Html form using JavaScript to display the table content java how to prevent no from unroundin off on clicking text box again in JSP and Jquery graph generation from xml design file display data from database in textbox when id entered in textbox Javascript Code for all fields how to get HTTP GET request value using javascript array Javascript Querry autocomplete(): Spring mvc with jquery: I am not getting correct value in the text filed. Please help me Create SpreadSheet same as excel using java applet Create SpreadSheet same as excel using java applet How to change focus among multiple select boxes? Write JQUERY Code Write JQUERY Code Converting jsp variable to java variable java

Ads

 
Advertisement null

Ads