Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class Scratch {
- static void wrong(int cheakCentury, int cheakDay, int cheakMonth, int cheakLetter, int cheakLength)
- {
- System.out.println(cheakCentury+" "+cheakDay+" "+cheakMonth+" "+cheakLetter);
- if(cheakLength == 1)
- {
- System.out.println("invalid IIN");
- }
- if(cheakMonth == 1)
- {
- System.out.println("wrong month");
- }
- if(cheakDay == 1)
- {
- System.out.println("wrong day");
- }
- if(cheakCentury == 1)
- {
- System.out.println("wrong Century");
- }
- if(cheakLetter == 1)
- {
- System.out.println("error: you enter letter");
- }
- if(cheakDay ==1 && cheakMonth == 1)
- {
- System.out.println("invalid IIN");
- }
- if(cheakCentury==1 || cheakDay==1 || cheakLetter==1 || cheakMonth==1 || cheakLength==1)
- {
- System.exit(0);
- }
- }
- public static void main(String[] args) {
- boolean wrongLength = false;
- Scanner in = new Scanner(System.in);
- String IIN = in.nextLine();
- System.out.println(IIN);
- if(IIN.length() != 12)
- {
- wrongLength = true;
- System.out.println("invalid IIN");
- System.exit(0);
- }
- boolean wrongLetter = false;
- for (int i = 0; i < IIN.length(); i++)
- {
- if (IIN.charAt(i) < '0' || IIN.charAt(i) > '9') {
- wrongLetter = true;
- System.out.println("invalid IIN: entered letter");
- System.exit(0);
- }
- }
- int cheakLength = wrongLength ? 1:0;
- 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 wrongMonth = false;
- boolean wrongDay = false;
- boolean wrongCentury = false;
- if (Month > 12 || Month <= 0)
- {
- wrongMonth = true;
- }
- if (Century > 6 || Century <= 0)
- {
- wrongCentury = true;
- }
- int leapYear = Year % 4;
- String monthout = "";
- switch (Month) {
- case 1: {
- monthout = "january";
- break;
- }
- case 2: {
- if (leapYear == 0)
- {
- if (Day > 29)
- {
- wrongDay = true;
- }
- else
- {
- monthout = "febuary";
- break;
- }
- }
- else
- {
- if (Day > 28)
- {
- wrongDay = true;
- } else
- {
- 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 cheakCentury = wrongCentury ? 1 : 0;
- int cheakDay = wrongDay ? 1 : 0;
- int cheakMonth = wrongMonth ? 1 : 0;
- int cheakLetter = wrongLetter ? 1 : 0;
- wrong(cheakCentury, cheakDay, cheakMonth, cheakLetter, cheakLength);
- System.out.println("test answer");
- int Age = 2019 - Year;
- int today = 18;
- int currentMonth = 4;
- if (Month >= currentMonth && Day > today || Month > currentMonth) {
- Age = Age - 1;
- }
- System.out.println(Year + " " + Month + " " + Day + " " + Century);
- System.out.println("Age: " + Age);
- System.out.println("Date of birthday: " + Day + " " + monthout + " " + Year);
- System.out.println(sex);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement