Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- public class LicensePlateTranslator {
- public static String[] database = {"C Cork", "CE Clare", "CN Cavan", "CW Carlow",
- "D Dublin", "DL Donegal", "G Galway", "KE Kildare", "KK Kilkenny", "KY Kerry",
- "L Limerick", "LD Longford", "LH Louth", "LM Leitrim", "LS Laois",
- "MH Meath", "MN Monaghan", "MO Mayo", "OY Offaly", "RN Roscommon",
- "SO Sligo", "T Tipperary", "W Waterford", "WH Westmeath",
- "WX Wexford", "WW Wicklow"};
- //
- public static void checkYear(String [] tempInputArray){
- int x,y,z;
- x=y=z=0;
- //tempInputArray[0] tu miesci sie pierwszy element tablicy rejestracyjnej, w tym miejscu masz te litery okreslajace rok.
- if (tempInputArray[0].length > 2){//jezeli jest wiecej niz 2 znaki to zakladam ze jest po 2k13.
- 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
- x = Integer.valueOf(tempInputArray[0][0]);
- y = Integer.valueOf(tempInputArray[0][1]);
- z = Integer.valueOf(tempInputArray[0][2]);
- year = year + x*10 + y; // tu policzy ci z ktorego roku, wez sobie kartke i to wylicz jak mi nie wierzysz.
- if (z ==1){
- System.out.println("This car was registered in first half of "+ year +" year");
- }
- if (z ==2){
- System.out.println("This car was registered in second half of "+ year +" year");
- }
- }
- if (tempInputArray[0].length == 2){//jezeli ma 2 znaki to zakladam ze jest przed 2k13. ta sama zasada dzialania.
- x = Integer.valueOf(tempInputArray[0][0]);
- y = Integer.valueOf(tempInputArray[0][1]);
- if(tempInputArray[0][0] ==8 ||tempInputArray[0][0] ==9 ){// w porownaniu do rozwiazania twojego ziomeczka jest troche roboty na okolo.
- year = 1900;// chociazby dlatego ze ja tutaj samemu i recznie przeliczam lata. Typ korzysta z wbudowanego parsera który zmienia stringi na Inty.
- year = year + x*10 + y;
- System.out.println("This car was registered in "+ year +" year");
- }
- if(tempInputArray[0][0] ==0){
- year = 2000;
- year = year + x*10 + y;
- System.out.println("This car was registered in "+ year +" year");
- }
- if (tempInputArray [0][0] =="1"){
- if (tempInputArray[0][1]=="1"){
- year = 2000;
- year = year + x*10 + y;
- System.out.println("This car was registered in "+ year +" year");
- }
- if (tempInputArray[0][1]=="2"){
- year = 2000;
- year = year + x*10 + y;
- System.out.println("This car was registered in "+ year +" year");
- }
- }
- }
- }
- public static void checkCounty (String []tempInputArray){//pewnie ciekawi cie co tu sie dzieje nie ?
- for (int i =0 ; i<database.length ; i++){// za pomoca funkcji length lapie ilosc elementow w tablicy database, cnie?
- String [] tempDatabaseRecord = database[i].split(" ");//pozniej po kolei wyciagam elementy z tablicy database i dziele je za pomoca splita na dwie czesci oddzielone spacja.
- if(tempInputArray[1]== tempDatabaseRecord[0]){//jezeli obie komorki w tablicy ktore zawieraja kod regionu/hrabstwa/ whateva sa takie same to idzim dalej
- System.out.println("The car was registered in : "+tempDatabaseRecord[1]);//wypisujemy nazwe ktora jest przypisdana do kodu.
- break;
- }
- }
- }
- public static void getSequenceNumber (String []tempInputArray){// wedlug wiki tak sie nazywa ten trzeci czlon tablicy rejestracyjnej, nie mnie oceniac
- System.out.println("With a sequence number of :"+tempDatabaseRecord[2]);
- }
- public static void checkPlates (String input){
- 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
- String [] inputArray = tempInput.split(" - "); // tu rozdzielak to kurestwo na mniejsze kawaleczki, znakiem podzialu jest spacja myslnik spacja.
- //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.
- checkYear(inputArray); //widzisz ta tablice dwie linijki wyzej nie? tutaj wstawilem ja w nawiasy zebym mogl z niej korzystac w innych funkcjach
- checkCounty(inputArray); // to samo co wyzej
- getSequenceNumber(inputArray);
- }
- public static void main(String[] args) {
- boolean exit = false;
- String inputPlate = "";
- while (!exit) {
- ListFill();
- Scanner scanner = new Scanner(System.in);
- System.out.println("-----[Igor Wojcieszek 7ITA]-----");
- System.out.println("1 - Enter License Plate");
- System.out.println("2 - Exit Program");
- int choice = scanner.nextInt();
- if (choice == 2) {
- exit = true;
- } else if (choice == 1) {
- System.out.println(" Insert a License plate ");
- inputPlate = scanner.nextLine();
- System.out.println(" Your license plate is: "+ inputPlate);
- } else {
- System.out.println(" Error Wrong number Fool ");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement