Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //ТЕМА_16//
- import java.util.Dictionary;
- import java.util.Scanner;
- import java.util.Hashtable;
- import java.util.Enumeration;
- public class UASD_2_200321 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- //MAKING A DICTIONARY, BY USING HASHTABLE//
- Dictionary<Integer, String> MonthsDictionary = new Hashtable<>();
- // KEY : VALUE//
- MonthsDictionary.put(1, "JANUARY");
- MonthsDictionary.put(2, "FEBRUARY");
- MonthsDictionary.put(3, "MARCH");
- MonthsDictionary.put(4, "APRIL");
- MonthsDictionary.put(5, "MAY");
- MonthsDictionary.put(6, "JUNE");
- MonthsDictionary.put(7, "JULY");
- MonthsDictionary.put(8, "AUGUST");
- MonthsDictionary.put(9, "SEPTEMBER");
- MonthsDictionary.put(10, "OCTOBER");
- MonthsDictionary.put(11, "NOVEMBER");
- MonthsDictionary.put(12, "DECEMBER");
- //ASKING THE USER//
- System.out.println("This is a program that allows you to search for month's name by it's number and the opposite.");
- System.out.println("Please, choose:\nNUMBER | NAME");
- String user = sc.nextLine().toLowerCase();
- //CHECKING FOR CONDITION//
- if(user.equals("number")) { //BY NUMBER//
- Enumeration<Integer> itemsKey = MonthsDictionary.keys(); //Enumerations of keys//
- Enumeration<String> itemsValue = MonthsDictionary.elements(); //Enumerations of values//
- System.out.println("Please, enter the month's number: ");
- String month_number = sc.nextLine();
- while (itemsKey.hasMoreElements()) {
- String currentKey = itemsKey.nextElement().toString();
- String currentValue = itemsValue.nextElement();
- if(currentKey.equals(month_number)){
- System.out.println("This month name is: " + currentValue);
- }
- }
- }else if(user.equals("name")){ //BY NAME//
- Enumeration<Integer> itemsKey = MonthsDictionary.keys(); //Enumerations of keys//
- Enumeration<String> itemsValue = MonthsDictionary.elements(); //Enumerations of values//
- System.out.println("Please, enter the month's name: ");
- String month_name = sc.nextLine().toUpperCase();
- while (itemsKey.hasMoreElements()) {
- String currentKey = itemsKey.nextElement().toString();
- String currentValue = itemsValue.nextElement();
- if(currentValue.equals(month_name)){
- System.out.println("This month number is: " + currentKey);
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment