Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.12 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. public class LicensePlateTranslator {
  4.  
  5.  
  6.     public static String[] database = {"C Cork", "CE Clare", "CN Cavan", "CW Carlow",
  7.         "D Dublin", "DL Donegal", "G Galway", "KE Kildare", "KK Kilkenny", "KY Kerry",
  8.         "L Limerick", "LD Longford", "LH Louth", "LM Leitrim", "LS Laois",
  9.         "MH Meath", "MN Monaghan", "MO Mayo", "OY Offaly", "RN Roscommon",
  10.         "SO Sligo", "T Tipperary", "W Waterford", "WH Westmeath",
  11.         "WX Wexford", "WW Wicklow"};
  12.     //
  13.  
  14.     public static void checkYear(String [] tempInputArray){
  15.         int x,y,z;
  16.         x=y=z=0;
  17.         //tempInputArray[0] tu miesci sie pierwszy element tablicy rejestracyjnej, w tym miejscu masz te litery okreslajace rok.
  18.         if (tempInputArray[0].length > 2){//jezeli jest wiecej niz 2 znaki to zakladam ze jest po 2k13.
  19.             int year = 2000;//w tempInputArray[0] miesci sie liczba np 132. I zapisuje je jako pojedyncze cyfry. tempInputArray[0][0] = 1, tempInputArray[0][1] = 3 tempInputArray[0][2] = 2
  20.             x = Integer.valueOf(tempInputArray[0][0]);
  21.             y = Integer.valueOf(tempInputArray[0][1]);
  22.             z = Integer.valueOf(tempInputArray[0][2]);
  23.  
  24.             year = year + x*10 + y; // tu policzy ci z ktorego roku, wez sobie kartke i to wylicz jak mi nie wierzysz.
  25.             if (z ==1){
  26.                 System.out.println("This car was registered in first half of "+ year +" year");
  27.             }
  28.             if (z ==2){
  29.                 System.out.println("This car was registered in second half of "+ year +" year");
  30.             }
  31.         }
  32.         if (tempInputArray[0].length == 2){//jezeli ma 2 znaki to zakladam ze jest przed 2k13. ta sama zasada dzialania.
  33.             x = Integer.valueOf(tempInputArray[0][0]);
  34.             y = Integer.valueOf(tempInputArray[0][1]);
  35.             if(tempInputArray[0][0] ==8 ||tempInputArray[0][0] ==9 ){// w porownaniu do rozwiazania twojego ziomeczka jest troche roboty na okolo.
  36.                 year = 1900;// chociazby dlatego ze ja tutaj samemu i recznie przeliczam lata. Typ korzysta z wbudowanego parsera który zmienia stringi na Inty.
  37.                 year = year + x*10 + y;
  38.                 System.out.println("This car was registered in "+ year +" year");
  39.             }
  40.             if(tempInputArray[0][0] ==0){
  41.                 year = 2000;
  42.                 year = year + x*10 + y;
  43.                 System.out.println("This car was registered in "+ year +" year");
  44.             }
  45.             if (tempInputArray [0][0] =="1"){
  46.                 if (tempInputArray[0][1]=="1"){
  47.                     year = 2000;
  48.                 year = year + x*10 + y;
  49.                 System.out.println("This car was registered in "+ year +" year");
  50.                 }
  51.                 if (tempInputArray[0][1]=="2"){
  52.                     year = 2000;
  53.                 year = year + x*10 + y;
  54.                 System.out.println("This car was registered in "+ year +" year");
  55.                 }
  56.  
  57.             }
  58.         }
  59.     }
  60.  
  61.     public static void checkCounty (String []tempInputArray){//pewnie ciekawi cie co tu sie dzieje nie ?
  62.         for (int i =0 ; i<database.length ; i++){// za pomoca funkcji length lapie ilosc elementow w tablicy database, cnie?
  63.             String [] tempDatabaseRecord = database[i].split(" ");//pozniej po kolei wyciagam elementy z tablicy database i dziele je za pomoca splita na dwie czesci oddzielone spacja.
  64.             if(tempInputArray[1]== tempDatabaseRecord[0]){//jezeli obie komorki w tablicy ktore zawieraja kod regionu/hrabstwa/ whateva sa takie same to idzim dalej
  65.                 System.out.println("The car was registered in : "+tempDatabaseRecord[1]);//wypisujemy nazwe ktora jest przypisdana do kodu.
  66.                 break;
  67.             }
  68.         }
  69.     }
  70.  
  71.     public static void getSequenceNumber (String []tempInputArray){// wedlug wiki tak sie nazywa ten trzeci czlon tablicy rejestracyjnej, nie mnie oceniac
  72.         System.out.println("With a sequence number of :"+tempDatabaseRecord[2]);
  73.     }
  74.  
  75.     public static void checkPlates (String input){
  76.         String tempInput = input; //tu za pomoca przekazania argumentu wywolania funkcji (ten dynks w nawiasie) przerzucam to co user podal w mainie do tego kawalka kodu bnc
  77.         String [] inputArray = tempInput.split(" - "); // tu rozdzielak to kurestwo na mniejsze kawaleczki, znakiem podzialu jest spacja myslnik spacja.
  78.         //zakladam ze kazda tablica wyglada mniej wiecej tak, xxxx yyyy zzzz  , iksy to rok który trzeba matematycznie ogarnac, igreki to kod, a zetki to chuj wie co.
  79.         checkYear(inputArray); //widzisz ta tablice dwie linijki wyzej nie? tutaj wstawilem ja w nawiasy zebym mogl z niej korzystac w innych funkcjach
  80.         checkCounty(inputArray); // to samo co wyzej
  81.         getSequenceNumber(inputArray);
  82.         }
  83.  
  84.     public static void main(String[] args) {
  85.         boolean exit = false;
  86.         String inputPlate = "";
  87.         while (!exit) {
  88.             ListFill();
  89.                         Scanner scanner = new Scanner(System.in);
  90.                         System.out.println("-----[Igor Wojcieszek 7ITA]-----");
  91.                         System.out.println("1 - Enter License Plate");
  92.                         System.out.println("2 - Exit Program");
  93.                         int choice = scanner.nextInt();
  94.                         if (choice == 2) {
  95.                             exit = true;
  96.                         } else if (choice == 1) {
  97.  
  98.                             System.out.println(" Insert a License plate ");
  99.                             inputPlate = scanner.nextLine();
  100.                             System.out.println(" Your license plate is: "+ inputPlate);
  101.  
  102.  
  103.                         } else {
  104.                             System.out.println(" Error Wrong number Fool ");
  105.  
  106.                         }
  107.                     }
  108.  
  109.                 }
  110.  
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement