Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class Scratch {
- static void checkLength(String IIN)
- {
- if(IIN.length() != 12) {
- System.out.println("wrong amount of IIN");
- System.exit(0);
- }
- }
- static void checkLetters(String IIN)
- {
- boolean Letter = false;
- for(int i=0; i<IIN.length(); i++)
- {
- if(IIN.charAt(i)<'0' || IIN.charAt(i)>'9')
- {
- System.out.println("Error symbol " + (i+1) + " is letter");
- Letter = true;
- }
- }
- if(Letter == true)
- {
- System.exit(0);
- }
- }
- static void checkData(String IIN)
- {
- String year = IIN.substring(0,2);
- String month = IIN.substring(2,4);
- String day = IIN.substring(4, 6);
- String century = IIN.substring(6, 7);
- int Year = Integer.parseInt(year);
- int Month = Integer.parseInt(month);
- int Day = Integer.parseInt(day);
- int Century = Integer.parseInt(century);
- boolean checkMonth = false;
- boolean checkDay = false;
- boolean checkCentury = false;
- boolean chekTrueIIN = false;
- if(Month > 12 || Month <= 0) // проверка Месяца
- {
- checkMonth = true;
- }
- if(Century > 6 || Century <=0) // проверка века и пола
- {
- checkCentury = true;
- }
- if(Month == 4 || Month == 6 || Month == 9 || Month == 11) // проверка месяца и дней
- {
- if(Day>30 || Day <= 0)
- {
- checkDay = true;
- }
- }
- else
- {
- if(Day > 31 || Day <= 0)
- {
- checkDay = true;
- }
- }
- int leapYear = Year%4;
- if(leapYear>0 && Month == 2) // проверка високосного года
- {
- if(Day > 28)
- {
- checkDay = true;
- }
- }
- if(leapYear == 0 && Month == 2)
- {
- if(Day > 29)
- {
- checkDay = true;
- }
- }
- if(Century == 5 && Year > 19 || Century == 6 && Year > 19)
- {
- chekTrueIIN = true;
- System.out.println("in the future invented a time machine?");
- }
- if(checkMonth == true)
- {
- System.out.println("Entered wrong month");
- }
- if(checkDay == true)
- {
- System.out.println("Entered wrong day");
- }
- if(checkCentury == true)
- {
- System.out.println("Entered wrong century");
- }
- if(checkCentury == true || checkDay == true || checkMonth == true || chekTrueIIN == true)
- {
- System.exit(0);
- }
- else
- {
- information(Year, Month, Day, Century);
- }
- }
- static void information(int Year, int Month, int Day, int Century )
- {
- String monthout = "";
- switch(Month)
- {
- case 1:
- {
- monthout = "january";
- break;
- }
- case 2:
- {
- monthout = "febuary";
- break;
- }
- case 3:
- {
- monthout = "march";
- break;
- }
- case 4:
- {
- monthout = "april";
- break;
- }
- case 5:
- {
- monthout = "may";
- break;
- }
- case 6:
- {
- monthout = "june";
- break;
- }
- case 7:
- {
- monthout = "jule";
- break;
- }
- case 8:
- {
- monthout = "august";
- break;
- }
- case 9:
- {
- monthout = "september";
- break;
- }
- case 10:
- {
- monthout = "october";
- break;
- }
- case 11:
- {
- monthout = "november";
- break;
- }
- case 12:
- {
- monthout = "december";
- break;
- }
- }
- String sex = "";
- switch(Century)
- {
- case 1:
- {
- Year = Year+1800;
- sex += "man";
- break;
- }
- case 3:
- {
- Year = Year+1900;
- sex += "man";
- break;
- }
- case 5:
- {
- Year = Year+2000;
- sex += "man";
- break;
- }
- case 2:
- {
- Year = Year+1800;
- sex += "woman";
- break;
- }
- case 4:
- {
- Year = Year+1900;
- sex += "woman";
- break;
- }
- case 6:
- {
- Year = Year+2000;
- sex += "woman";
- break;
- }
- }
- int Age = 2019 - Year;
- int currentDay = 24;
- int currentMonth = 4;
- if(Month <= currentMonth && Day < currentDay)
- {
- Age = Age-1;
- }
- System.out.println("Age: "+Age);
- System.out.println("Date of birthday: "+Day+" "+monthout+" "+Year);
- System.out.println(sex);
- }
- public static void main(String[] args)
- {
- Scanner in = new Scanner(System.in);
- String IIN = in.nextLine();
- checkLength(IIN);
- checkLetters(IIN);
- checkData(IIN);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement