YoannaSt173

tema 23

May 2nd, 2020
553
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.24 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class dictionery {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.         String command="";
  7.  
  8.         Dictionary geek = new Hashtable();
  9.  
  10.         while (!command.equals("end")) {
  11.             command = scan.nextLine().toLowerCase();
  12.             if (command.equals("add")) {
  13.                 System.out.println("Enter student number:");
  14.                String number = scan.nextLine().toLowerCase();
  15.                 System.out.println("Enter student name:");
  16.                 String name = scan.nextLine().toLowerCase();
  17.                 geek.put(number,name );
  18.  
  19.             }else if(command.equals("rem")){
  20.                 System.out.println("Enter student number to remove:");
  21.                 String remove = scan.nextLine().toLowerCase();
  22.                 geek.remove(remove);
  23.             }else if(command.equals("cnt")){
  24.                 System.out.println("\nSize of Dictionary : " + geek.size());
  25.             }else if(command.equals("prn")){
  26.                 for (Enumeration i = geek.elements(); i.hasMoreElements();)
  27.                 {
  28.                     System.out.println("Value in Dictionary : " + i.nextElement());
  29.                 }
  30.             }
  31.         }
  32.  
  33.     }
  34. }
Add Comment
Please, Sign In to add comment