asmit
java beginner
1 Answer(s)      9 months ago
Posted in : Java Beginners

Hi

i have a methd that is public static insert ( map p), i have passed a java map object in this method , so i want to store employee infrmation in haspmap and how to find highest salery and afetr public static inserty(map p) {} what code i will write,

View Answers

August 17, 2012 at 2:38 PM


Here is an example that stores the employee information in a list and display the highest salary.

import java.io.*;
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 SalaryComparator implements Comparator{
    public int compare(Object emp1, Object emp2){
        int sal1 = ((Employee)emp1).getSalary();        
        int sal2 = ((Employee)emp2).getSalary();

        if(sal1 > sal2)
            return 1;
        else if(sal1 < sal2)
            return -1;
        else
            return 0;    
    }
}

public class EmployeeSalary {

public static void main(String[] args) throws Exception {
List<Employee> list = new ArrayList<Employee>();
list.add(new Employee("A","Delhi",10000));
list.add(new Employee("B","Mumbai",20000));
list.add(new Employee("C","Chennai",15000));
list.add(new Employee("D","Kolkata",12000));
System.out.println(" ");
int count=0;
int salary=0;
               Collections.sort(list,new SalaryComparator());
                for(Employee data: list){
                salary=data.getSalary();
                } 
                System.out.println("Highest salary is: "+salary);
   }
}









Related Pages:
Beginner
Beginner  how to call a gui class from applet class   Hello Friend, Please visit the following link: http://www.roseindia.net/java/example/java/applet/SApplet.shtml Thanks
beginner
beginner  provide a simple java exception program that uses try , catch, throw and finally blocks
java bEGINNER
java bEGINNER  WHAT IS THE BEST WAYS,BOOKS AND pRACTICAL IMPLEMENTATION TECHNIQUES FOR A BEGINNER
java beginner
java beginner  hai a i'm beginner 2 java... i want to fetch data from database using combo box(drop down list) without using javascript...when i click list(ex:countrys should b selected)selected country should get inserted
JAVA BEGINNER
JAVA BEGINNER  IS JAVA PURE OBJECT ORIENTED
Java Beginner
Java Beginner  can we declare a class inside an interface? where this type of declaration required? give one example
java beginner
java beginner  Hi i have a methd that is public static insert ( map p), i have passed a java map object in this method , so i want to store employee infrmation in haspmap and how to find highest salery and afetr public
Java Beginner
Java Beginner  To reverse a every other word in a string. Example :- If the input is "This is a line of message" the output should be "sihT is a line fo message
java beginner
java beginner  Hi using hashcode() and equal() method and hashmap object how to compare employee lastname and firstname ,display in console
java beginner
java beginner  Hi how to sort list of element containing a data object like date of birth of employee. display employee in youngest first and oldest last , using one of the collection class for sorting
java beginner
java beginner  Write a program that will grade the students quiz. The program will ask the user to enter the number of the questions in the quiz, the right answer for each question and save it in array. The program will ask
java beginner
java beginner  HI I am swetha iam confused when to use service(), doget(), dopost() method in servlets   Any request from client are handled initially by the service() method before delegating to the doXxx() methods
Nag(Beginner)
Nag(Beginner)  sir i am new to java.. i want to know what topics comes under core java, adv. java and also the remaining topics... plz tell me   Java Tutorials
jAVA BEGINNER PROBLEMS
jAVA BEGINNER PROBLEMS  I need the program that takes from standard input an expression without left parenthesis and prints the equivalent infix expression with the parenthesis inserted??? Like EXAMPLE: 1+2)3-4)5-6
Java beginner - Java Beginners
Java beginner  what is the diffrence between abstraction and interface? with coding
Generating Random Numbers to Fill array. Java Beginner needing help!
Generating Random Numbers to Fill array. Java Beginner needing help!  Hello all! I am new to this site, and Java programming. My problem is: Write...() methods. I am new to Java programming and this seems mind blowing to me :( I
Java guide
Java guide       Any beginner requires guidance to start with. A beginner in the field of java... practical guide to the beginner and experienced java programmer. These tutorials have
Java Tutorial
Java Tutorials If you are a beginner and looking for the Java tutorials to learn java programming language from scratch then this the best place to start with the Java programming language. Java programming language contains huge
SQL for Beginner
SQL for Beginner      ... the easiest elaborative examples for the beginner. The beginner will reached into the immediate result as the SQL command is submitted. It bring the beginner
beginner need help with online ordering program please
beginner need help with online ordering program please  I have created a program for an online ordering system and now have to add error handling and a few other things my teacher doesn't teach well is there a template I can go
SQL Tutorials for Beginner
SQL Tutorials for Beginner       SQL for Beginner The Tutorial brings  a unique introduction on SQL for beginners, who want to learn
Beginner Guide to Linux Server
Beginner Guide to Linux Server Introduction Linux is know for its security, performance, reliability. Many business units are looking towards Linux... flavor of  Linux.  Which Linux Flavor? As a beginner you can try Red Hat
Beginner Guide to Linux Server
Beginner Guide to Linux Server                 ...? As a beginner you can try Red Hat 9.0 or Mandrake 10 for setting up your server
My Favorite Java Books
Java NotesMy Favorite Java Books My standard book questions When I think... aren't going to give the absolute beginner a simple enough start, but if you... language and want to learn Java, these are good books. Head First Java
How to Java Program
How to Java Program       If you are beginner in java , want to learn and make career in the Java... for the respective operating system. Java Program for Beginner Our first
Develop-JSF Application
Develop-JSF Application             This section is very useful for any beginner in the field of JSF (Java Server Faces) framework of Java. This example
java - Java Beginners
Java beginner advanced tutorial  Do you have any series of advance tutorials for Java beginner
Java
Java  Hi, What is Java programming language, how a beginner can learn java and become expert? Give me answer ASAP. Thanks
Programs in java
Programs in java  Hi, What are the best programs in java for a beginner? Thanks
Online Java Training for Beginners
for the beginners. The Online Java Programming course for the beginner's...Online Java Training for Beginners The online java training for beginners teaches the students that what Java programming is all about and what are the uses
Basics of Social Media Marketing for Beginner
Social Media Marketing Basics for the Beginner and Advanced Basics of Social media marketing is more important to many types of online businesses. Some business people are heavily involved in this type of social media marketing while
java - Framework
java  how use dao class in projects.give a simple application so that it is easy for a beginner thnx
Java - Swing AWT
How to start learning Java   I am a Java Beginner ...so, please guide me how to start
Java for beginners - Java Beginners
Java for beginners  Hi! I would like to ask you the easiest way to understand java as a beginner? Do i need to read books in advance or is there for me to know first before i start? Thanx!  Hi friend, For java
java - Java Beginners
java  hi i am a beginner in java. I have to make a mini project in java. I think about to develop a web page using java so any one please guide me how to develop web page using java
XML Tutorials
-structured and so easy to grasp that they quickly shift a beginner to XML-Java... Java XML processing APIs. Tutorial starts with the brief introduction to XML... examples to help you master using XML with Java. Advance topics like JAXP
Serialization - Java Interview Questions
Serialization Interface  I am a beginner in java.. What is serialization? what happens if we implement Serialization interface? Thanks in advance
Java faqs
Java faqs  Hello Java Developers, I am beginner in Java and trying to find the best java faqs. Where I can find java faqs? Thanks   Hi, Please see the thread java faq Thanks
Free Java Download
Free Java Download   Hi, I am beginner in Java and trying to find the url to download Java. Can anyone provide me the url of Free Java Download ? Is Java free? Thanks
Simple Java Projects
Simple Java Projects  Hi, I am beginner in Java and trying to find Simple Java Projects to learn the different concepts on Java. Can anyone tell me where to get it? Thanks
Learn java
Learn java  Hi, I am absolute beginner in Java programming Language. Can anyone tell me how I can learn: a) Basics of Java b) Advance Java c) Java frameworks and anything which is important. Thanks

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.