Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fpd;
- import java.util.Scanner;
- public class validace {
- public static Boolean validate(String x) {
- if (xy.length() < 11 || xy.length() > 11) {
- return false;
- }
- String ownerCode = xy.substring(0, 3);
- System.out.println("owner code: " + ownerCode);
- String productGroupCode = xy.substring(3, 4); // U, Z, J
- System.out.println("product group code: " + productGroupCode);
- String productNumber = xy.substring(4, 10);
- System.out.println("product number: " + productNumber);
- String check = xy.substring(10, 11);
- System.out.println("check: " + check);
- for(int i = 0; i < ownerCode.length(); i++) {
- char c = ownerCode.charAt(i);
- if(c < 'A' || c > 'Z') {
- System.out.println("neplatny znak: " + c);
- return false;
- }
- }
- if (
- productGroupCode.equals("U") || productGroupCode.equals("J") || productGroupCode.equals("Z")
- ) {
- } else {
- return false;
- }
- for(int i = 0; i < productNumber.length(); i++) {
- char c = productNumber.charAt(i);
- if(c < '0' || c > '9') {
- System.out.println("neplatny znak v product number: " + c);
- return false;
- }
- }
- int soucet = 0;
- int mocnina2 = 1;
- for(int i = 0; i < xy.length() - 1; i++) {
- char c = x.charAt(i);
- int aktualniCislo = -1;
- if(c >= 'A' && c <= 'Z') {
- if(c == 'A') {
- aktualniCislo = 10;
- }
- if(c == 'B') {
- aktualniCislo = 12;
- }
- if(c == 'C') {
- aktualniCislo = 13;
- }
- if(c == 'D') {
- aktualniCislo = 14;
- }
- if(c == 'E') {
- aktualniCislo = 15;
- }
- if(c == 'F') {
- aktualniCislo = 16;
- }
- if(c == 'G') {
- aktualniCislo = 17;
- }
- if(c == 'H') {
- aktualniCislo = 18;
- }
- if(c == 'I') {
- aktualniCislo = 19;
- }
- if(c == 'J') {
- aktualniCislo = 20;
- }
- if(c == 'K') {
- aktualniCislo = 21;
- }
- if(c == 'L') {
- aktualniCislo = 23;
- }
- if(c == 'M') {
- aktualniCislo = 24;
- }
- if(c == 'N') {
- aktualniCislo = 25;
- }
- if(c == 'O') {
- aktualniCislo = 26;
- }
- if(c == 'P') {
- aktualniCislo = 27;
- }
- if(c == 'Q') {
- aktualniCislo = 28;
- }
- if(c == 'R') {
- aktualniCislo = 29;
- }
- if(c == 'S') {
- aktualniCislo = 30;
- }
- if(c == 'T') {
- aktualniCislo = 31;
- }
- if(c == 'U') {
- aktualniCislo = 32;
- }
- if(c == 'V') {
- aktualniCislo = 34;
- }
- if(c == 'W') {
- aktualniCislo = 35;
- }
- if(c == 'X') {
- aktualniCislo = 36;
- }
- if(c == 'Y') {
- aktualniCislo = 37;
- }
- // ...
- if (c == 'Z') {
- aktualniCislo = 38;
- }
- }
- if(c >= '0' && c <= '9') {
- aktualniCislo = c - 48;
- }
- if (aktualniCislo != -1) {
- soucet += aktualniCislo * mocnina2;
- mocnina2 = mocnina2 * 2;
- } else {
- System.out.println("Tohle se nemelo nikdy stat");
- }
- }
- System.out.println("soucet: " + soucet);
- int poDeleni = soucet / 11;
- int poVynasobeniZpet = poDeleni * 11;
- int checkJakoCislo = Integer.parseInt(check);
- if (soucet - poVynasobeniZpet != checkJakoCislo) {
- System.out.println("soucet nesedi");
- return false;
- }
- return true;
- }
- public static void main(String[] args) {
- System.out.print("Zadej owner code, product group code, product number, check př: CSIU2000820 ");
- Scanner scanner = new Scanner(System.in);
- String x = scanner.next();
- System.out.println("validate: " + validate(x));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment