Cute Happy Ghost
본문 바로가기
JAVA/Project

전화번호부 검색기능

by JENN_tech7 2020. 10. 21.
728x90
SMALL

같은 이름, 같은 나이, 같은 뒷자리가 있을수도있으니 추가

팀원들 도움으로 해결하였다....

checksum이라는 같으면 0

public void search() {
		for(;;) {
			System.out.println("(1) 이름으로 검색");
			System.out.println("(2) 나이로 검색");
			System.out.println("(3) 전화번호로 검색");
			selectnum = sc.nextInt();

			if (selectnum == 1) {
				System.out.print("이름 입력 : ");
				String sreachname = sc.next();//이름입력받기
				System.out.println("No\t 이름\t 나이\t 전화번호        ID\t 사용자\t");
				System.out.println("------------------------------------------------------------");
				{
					for (int i = 0; i < people.size(); i++) {
						if (sreachname.equals(people.get(i).getName())) {
							String Ph = people.get(i).getPhone();
							System.out.println((i+1)+"\t" +people.get(i)+(Ph.substring(0,4))+ "-" +(Ph.substring(4,8))+"|"+ namecode);
							checknum = 1;
							continue;
						}
					}
					if(checknum == 1) {
						checknum = 0;
						break;
					}
					else if(checknum == 0) {
						System.out.println("검색결과 없음.");
						break;
					}
				} //for
			}


			if (selectnum == 2) {
				System.out.print("나이 입력 : ");
				int srAge = sc.nextInt();//이름입력받기
				System.out.println("No\t 이름\t 나이\t 전화번호        ID\t 사용자\t");
				System.out.println("------------------------------------------------------------");
				{
					for (int i = 0; i < people.size(); i++) {
						if (srAge==(people.get(i).getAge())) {
							String Ph = people.get(i).getPhone();
							System.out.println((i+1)+"\t" +people.get(i)+(Ph.substring(0,4))+ "-" +(Ph.substring(4,8))+"|"+ namecode);
							checknum = 1;
							continue;
						}
					}
					if(checknum == 1) {
						checknum = 0;
						break;
					}
					else if(checknum == 0) {
						System.out.println("검색결과 없음.");
						break;
					}
				} //for
			}
			
			if (selectnum == 3) {
				System.out.print("전화번호 입력(뒤4자리를 입력해주세요) : ");
				String srPhone = sc.next();//전화번호입력받기
				System.out.println("No\t 이름\t 나이\t 전화번호        ID\t 사용자\t");
				System.out.println("------------------------------------------------------------");
				{
					for (int i = 0; i < people.size(); i++) {
						String Ph = people.get(i).getPhone();
						if (srPhone.equals(Ph.substring(4,8))) {
							System.out.println((i+1)+"\t" +people.get(i)+(Ph.substring(0,4))+ "-" +(Ph.substring(4,8))+"|"+ namecode);
							checknum = 1;
							continue;
						}
					}
					if(checknum == 1) {
						checknum = 0;
						break;
					}
					else if(checknum == 0) {
						System.out.println("검색결과 없음.");
						break;
					}
				} //for
			}
728x90
LIST

'JAVA > Project' 카테고리의 다른 글

Todolist  (0) 2020.11.06
전화번호부 검색, 출력 메소드  (0) 2020.10.21

댓글