package SocialSecurityNumber_02;

import java.util.Scanner;

public class MainClass01 {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		System.out.print("주민등록번호 : ");
		String num = in.nextLine();

		CheckNum01 chk = new CheckNum01(num);
		chk.play();
		
	}
package SocialSecurityNumber_02;

import java.util.Calendar;
import java.util.Scanner;

class CheckNum01 {
	StringBuffer num;
	int select;
	int year, month, day, sex, local, age;

	// 생성자
	CheckNum01(String temp) {
		// StringBuffer을 사용하라고 할까봐 넘겨주었는데 그닥...
		this.num = new StringBuffer(temp);

		char firstNum = num.charAt(7);

		this.year = Integer.parseInt(num.substring(0, 2));
		this.month = Integer.parseInt(num.substring(2, 4));
		this.day = Integer.parseInt(num.substring(4, 6));

		switch (firstNum) {
		case '1':
			this.year += 1900;
			this.sex = 0;
			this.local = 0;
			break;
		case '2':
			this.year += 1900;
			this.sex = 1;
			this.local = 0;
			break;
		case '3':
			this.year += 2000;
			this.sex = 0;
			this.local = 0;
			break;
		case '4':
			this.year += 2000;
			this.sex = 1;
			this.local = 0;
			break;
		case '5':
			this.year += 1900;
			this.sex = 0;
			this.local = 1;
			break;
		case '6':
			this.year += 1900;
			this.sex = 1;
			this.local = 1;
			break;
		case '7':
			this.year += 2000;
			this.sex = 0;
			this.local = 1;
			break;
		case '8':
			this.year += 2000;
			this.sex = 1;
			this.local = 1;
			break;
		case '9':
			this.year += 1800;
			this.sex = 0;
			this.local = 0;
			break;
		case '0':
			this.year += 1800;
			this.sex = 1;
			this.local = 0;
			break;
		}
	}

	// 원하는 것을 출력할 수 있도록 물어보는 메서드
	void play() {
		// while(select != 0)
		outerLoop: while (true) {
			System.out
					.println("MENU > 1: 생년월일 / 2: 나이 / 3: 성별 / 4: 내/외국인 / 0: Quit");
			System.out.print("Select Number-> ");
			Scanner in = new Scanner(System.in);
			select = in.nextInt();

			switch (select) {
			case 1:
				brithday();
				break;
			case 2:
				ageChk();
				break;
			case 3:
				sexChk();
				break;
			case 4:
				localChk();
				break;
			case 0:
				break outerLoop;
			// return;
			}
			System.out.println();
		}
		System.out.println("Quit...");
	}

	void brithday() {
		System.out.println("사용자는 '" + year + "년 " + month + "월 " + day
				+ "일생'입니다.");
	}

	void ageChk() {
		Calendar date = Calendar.getInstance();
		age = (date.get(Calendar.YEAR)) - year + 1;
		System.out.println("사용자의 나이는 '" + age + "'살 입니다.");
	}

	void sexChk() {
		System.out.println("사용자의 성별은 '" + (sex != 1 ? "남자" : "여자") + "'입니다.");
	}
	
	void localChk() {
		System.out.println("사용자는 '" +  (local != 1 ? "내국인" : "외국인") + "'입니다.");
	}
}

+ Recent posts