Presentation is loading. Please wait.

Presentation is loading. Please wait.

주소록 프로그램.

Similar presentations


Presentation on theme: "주소록 프로그램."— Presentation transcript:

1 주소록 프로그램

2 1. 시나리오 프로그램을 실행하면 우선 어떤 작업을 할지 메뉴를 선택합니다.
메뉴 중 원하는 작업을 선택하고 그에 해당하는 작업을 수행합니다. 선택한 작업을 모두 수행하고 난 후엔 다시 선택지로 돌아옵니다. 원하는 작업을 마친 후, 프로그램 종료메뉴를 선택하면 프로그램을 종료합니다. ex) 1. 새로운 데이터 입력 2. 데이터 삭제 3. 데이터 검색 4. 리스트 보기 5. 프로그램 종료

3 AddressListTestDrive
2. 다이어그램 AddressList -userName; String[] -phoneNumber; String[] -userAddress; String[] -temp; int +AddressList(); +insertData(int); int +removeData(); void +findData(); void +printList(); void +memual(); void MyAddressAccess -selectMenuStr; String -selectMenu; int -idOkay; boolean -x; int +selectMenuDrive(); void +getListIndex(); int AddressListTestDrive +main(String[] args); void

4 3. 구현코드 import java.io.*; class AddressList {
private String[] userName; //이름 private String[] phoneNumber; //연락처 private String[] userAddress; //주소 private int temp = 0; public AddressList() { userName = new String[100]; //이름 phoneNumber = new String[100]; //연락처 userAddress = new String[100]; } public int insertData(int x)throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

5 String tempUserName = " ";
String tempPhoneNumber = " "; String tempAddress = " "; System.out.println("데이터를 입력하세요"); System.out.print("이름 : "); tempUserName = in.readLine(); userName[x] = tempUserName; System.out.print("전화번호 : "); tempPhoneNumber = in.readLine(); phoneNumber[x] = tempPhoneNumber; System.out.print("주소 : "); tempAddress = in.readLine(); userAddress[x] = tempAddress; x = x+1; temp = x; return x; }//입력

6 public void removeData() throws IOException
{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int i=0; boolean idOkay = true; String tempRemoveData; System.out.println("삭제 할 데이터를 입력하세요 "); tempRemoveData = in.readLine(); while(idOkay) if(tempRemoveData.equals(userName[i])) userName[i] = null; phoneNumber[i] = null; userAddress[i] = null; idOkay = false; } i = i + 1; }//삭제

7 public void findData() throws IOException
{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int i=0; boolean idOkay = true; String tempFindData; System.out.println("찾을 데이터를 입력하세요 "); tempFindData = in.readLine(); while(idOkay) if(tempFindData.equals(userName[i])) System.out.println(userName[i]); System.out.println(phoneNumber[i]); System.out.println(userAddress[i]); idOkay = false; } i = i + 1; }//검색

8 public void printList(int x) {
if(x==0){ System.out.println("출력할 데이타가 없습니다 "); }else{ for(int i=0; i<x; i++){ System.out.println(userName[i]); System.out.println(phoneNumber[i]); System.out.println(userAddress[i]+ "\n"); } }//검색 public void menual(){ System.out.print("\n메뉴를 선택하세요\n"); System.out.print("1.새로운 데이터 입력\n"); System.out.print("2.데이터 삭제\n"); System.out.print("3.데이터 검색\n"); System.out.print("4.리스트 보기\n"); System.out.print("5.프로그램 종료\n"); System.out.print("->");

9 class MyAddressAccess
{ private String selectMenuStr; //메뉴의 번호를 지정받는 변수 private int selectMenu; private boolean idOkay = true; private int x=0; public int getListIndex() return x; } public void selectMenuDriven() throws IOException BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); AddressList accessList = new AddressList(); while(idOkay) accessList.menual(); selectMenuStr = in.readLine(); selectMenu = Integer.parseInt(selectMenuStr);

10 switch (selectMenu) { case 1: x= accessList.insertData(x); break; case 2: accessList.removeData(); break; case 3: accessList.findData(); break; case 4: accessList.printList(x); break; case 5: idOkay = false; break; } //메뉴를 결정 class AddressListTestDrive public static void main(String[] args) throws IOException MyAddressAccess userAddressList = new MyAddressAccess(); userAddressList.selectMenuDriven();

11 4. 실행화면

12

13

14

15

16

17

18 - 끝 -


Download ppt "주소록 프로그램."

Similar presentations


Ads by Google