google.com, pub-4617457846989927, DIRECT, f08c47fec0942fa0 Learn to enjoy every minute of your life.Only I can change my life.: Java program for hash table

Sunday, February 10, 2019

Java program for hash table


import  java.util.*;
import java.lang.*;
import java.io.*;
class   hashtable
{
        static Hashtable<String,Double> stud=new Hashtable<String,Double>();
              public  static void main(String args[])
        {
                BufferedReader br=new BufferedReader(new InputStreamReader(System.in));               
                do                {
                        System.out.println("****************MENU*****************");
                        System.out.println("1:ACCEPT RECORD\n2:DISPLAY ALL                      RECORDS\n3:FIND HIGHEST\n4:EXIT");
                        System.out.println("\nEnter your choice:");
                        int ch=0;
                        try
                        {
                                ch=Integer.parseInt(br.readLine());
                        }
                        catch(IOException e)
                        {
                                System.out.println(e);
                        }
                        switch(ch)
                        {
                                case 1:
                                        accept();
                                        break;
                                case 2:
                                        displayall();
                                        break;
                                case 3:
                                        fhigh();
                                        break;
                             




                                    case 4:
                                        System.exit(0);
                                default:
                                        System.out.println("You entered wrong choice! TRY AGAIN!!");
                                        break;
                         }
               }while(true);
      }
               public static void accept()
               {
                        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                        String name="";
                        Double d=0.0;
                        System.out.println("Enter the name:");
                        try
                        {
                                name=br.readLine();
                                System.out.println("Enter the percentage:");
                                d=Double.parseDouble(br.readLine());
                        }
                        catch(IOException e)
                        {
                                System.out.println(e);
                        }

                        stud.put(name,d);
                }
                public static void displayall()
                {
                        Enumeration keys=stud.keys();
                        while(keys.hasMoreElements())
                        {
                                String key=(String)keys.nextElement();
                                System.out.println(key+"="+stud.get(key));
                        }
                }
                public static void fhigh()
                {
                      






                         Double max=0.0;
                        Enumeration keys=stud.keys();
                        while(keys.hasMoreElements())
                        {
                                String key=(String)keys.nextElement();
                                if(max<stud.get(key))
                                        max=stud.get(key);
                        }      
                        System.out.println("Highest Marks="+max);
                }
        
}
                       

*****************************************************************
OUTPUT
******************************************************************



Enter your choice:
1
Enter the name:
vijay
Enter the percentage:
71
****************MENU*****************
1:ACCEPT RECORD
2:DISPLAY ALL RECORDS
3:FIND HIGHEST
4:EXIT

Enter your choice:
1
Enter the name:
ajay
Enter the percentage:
77
****************MENU*****************
1:ACCEPT RECORD
2:DISPLAY ALL RECORDS
3:FIND HIGHEST
4:EXIT

Enter your choice:
1
Enter the name:
 atul
Enter the percentage:
81
****************MENU*****************
1:ACCEPT RECORD
2:DISPLAY ALL RECORDS
3:FIND HIGHEST
4:EXIT

शिव भोलेनाथ स्तुति

 जय शिवशंकर, जय गंगाधर, करुणा-कर करतार हरे,   जय कैलाशी, जय अविनाशी, सुखराशि, सुख-सार हरे जय शशि-शेखर, जय डमरू-धर जय-जय प्रेमागार हरे,   जय ...