Advertisement
Capple

Untitled

May 8th, 2020
1,859
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.60 KB | None | 0 0
  1. import java.lang.reflect.Array;
  2. import java.util.Scanner;
  3.  
  4. /**
  5.  * PersonalCodeBehaviour
  6.  */
  7. interface PersonalCodeBehaviour {
  8.  
  9.     public String getGender();
  10.  
  11.     public String[] getBirthday(String isikukood);
  12.  
  13.     public String getYear(String[] birthdayArray);
  14.  
  15.     public String getMonth(String[] birthdayArray);
  16.  
  17.     public String getDay(String[] birthdayArray);
  18. }
  19.  
  20.  
  21. class EstonianID implements PersonalCodeBehaviour {
  22.  
  23.     private String isikukood;
  24.  
  25.     public EstonianID(String isikukood) {
  26.         this.isikukood = isikukood;
  27.         String[] birthdayArray = isikukood.split("-", 3);
  28.     }
  29.  
  30.     // public int getGender(String gender) {
  31.     //     if (gender == "mees") {
  32.     //         return 1;
  33.     //     } else if (gender == "naine") {
  34.     //         return 2;
  35.     //     } else {
  36.     //         return 0;
  37.     //     }
  38.     // }
  39.  
  40.     public String[] getBirthday() {
  41.         String[] birthdayArray = isikukood.split("-", 3);
  42.         return birthdayArray;
  43.     }
  44.  
  45.     public String getYear() {
  46.         String year = birthdayArray[2];
  47.         return year;
  48.     }
  49.  
  50.     public String getMonth(String[] birthdayArray) {
  51.         String month = birthdayArray[1];
  52.         return month;
  53.     }
  54.  
  55.     public String getDay(String[] birthdayArray) {
  56.         String day = birthdayArray[0];
  57.         return day;
  58.     }
  59.  
  60.     public String getGender(String isikukood) {
  61.         String gender =  String.valueOf(isikukood.indexOf(0));
  62.         return gender;
  63.  
  64.     }
  65.  
  66. }
  67.  
  68.  
  69. class Main {
  70.     public static void main(String[] args) {
  71.         Scanner scanner = new Scanner(System.in);
  72.         System.out.println("Eesti ID - 1 | Soome ID - 2");
  73.         int option = scanner.nextInt();
  74.         // EstonianID estonian = new EstonianID();
  75.         // FinnishID finnish = new FinnishID();
  76.         if (option == 1) {
  77.            
  78.             option = scanner.nextInt();
  79.             //scanner.nextLine();
  80.             if (option == 1) {
  81.             System.out.println("Sisestage oma isikukood: ");
  82.             String isikukood = scanner.nextLine();
  83.             EstonianID estonian = new EstonianID(isikukood);
  84.             System.out.println(estonian);
  85.  
  86.             } else if (option == 2) {
  87.             System.out.println("Sisestage oma isikukood: ");
  88.             String isikukood = scanner.nextLine();
  89.             EstonianID estonian = new EstonianID(isikukood);
  90.  
  91.             } else {
  92.                 System.out.println("Palun sisestage kas 1 voi 2!");
  93.             }
  94.  
  95.             scanner.close();
  96.  
  97.         }
  98.  
  99.  
  100.     }
  101. }
  102.  
  103. // public class FinnishID implements PersonalCodeBehaviour {
  104.  
  105. // }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement