자바(Java) 프로그래밍 과제 - #7 - 문제정의 및 분석, 소스코드 및 설명, 실행결과 및 설명
본 자료는 3페이지 의 미리보기를 제공합니다. 이미지를 클릭하여 주세요.
닫기
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
해당 자료는 3페이지 까지만 미리보기를 제공합니다.
3페이지 이후부터 다운로드 후 확인할 수 있습니다.

목차

1. 문제정의 및 분석
2. 소스코드 및 설명
3. 실행결과 및 설명
4. 결론

본문내용

한꺼번에 파일에 쓴다. */
bw.flush();
}
/* 출력을 위한 객체를 닫는다. */
bw.close();
}
public void delete(String deleteFile) throws IOException{
/* File 객체를 인수로 출력 스트림 객체를 만든다. */
for(int index = 0; index < List.size(); index++){
address = List.get(index); //List에 있는 address객체를 순서대로 받아온다.
/* for문을 돌다가 같은 이름이 발견되면 */
if(deleteFile.equals((String)address.strName)){
List.remove(index); //List에서 해당 index를 삭제
System.out.println(deleteFile + "이 삭제 되었습니다.");
}
}
}
/* 주소록 수정 */
public void modify(String searchFile, String modifyFile) throws IOException{
for(int index = 0; index < List.size(); index++){
address = List.get(index); //List에 있는 address객체를 순서대로 받아온다.
/* for문을 돌다가 같은 이름이 발견되면 */
if(searchFile.equals((String)address.strName)){
address.strName = modifyFile; //수정할 이름 Data타입에 삽입하고
List.set(index, address); //수정된 Data타입을 ArrayList에 교체한다.
}
}
}
}
==================================================================================
import java.io.*;
public class Main {
public static void main(String[] args) {
BufferedReader dis = new BufferedReader(new InputStreamReader(System.in));
AddressBook ab = null;
int iMenu = 0;
try{
System.out.println("주소록을 초기화 합니다.");
ab = new AddressBookImpl01();
System.out.print("주소록 파일 이름을 입력하세요... ");
ab.init(new String(dis.readLine()));
while(iMenu != 6){
System.out.println("================================");
System.out.println(" 0. 주소록 파일 불러오기 ");
System.out.println(" 1. 주소 추가하기");
System.out.println(" 2. 주소 삭제하기");
System.out.println(" 3. 주소 변경하기");
System.out.println(" 4. 주소록 파일 저장하기");
System.out.println(" 5. 주소록 다른 파일에 저장하기");
System.out.println(" 6. 종료하기");
System.out.println("================================");
System.out.print("메뉴의 번호를 입력하세요 : ");
iMenu = Integer.parseInt(dis.readLine());
switch(iMenu) {
case 0: //주소록 파일 불러오기
System.out.print("주소록 파일 이름을 입력하세요...");
ab.init(new String(dis.readLine()));
break;
case 1: //주소 추가하기
String strName;
String strAddress;
String strPhone;
System.out.print("이 름 : ");
strName = new String(dis.readLine());
System.out.print("주 소 : ");
strAddress = new String(dis.readLine());
System.out.print("전화번호 : ");
strPhone = new String(dis.readLine());
ab.add(strName, strAddress, strPhone);
break;
case 2: //주소 삭제하기
String deleteFile;
System.out.print("삭제할 이름을 입력하세요 : ");
deleteFile = new String(dis.readLine());
ab.delete(deleteFile);
break;
case 3: //주소 변경하기
String searchFile;
String modifyFile;
System.out.print("검색할 이름을 입력하세요 : ");
searchFile = new String(dis.readLine());
System.out.print("수정할 이름을 입력하세요 : ");
modifyFile = new String(dis.readLine());
ab.modify(searchFile, modifyFile);
break;
case 4: //주소록 파일 저장하기
ab.save();
break;
case 5: //주소록 다른 파일에 저장하기
System.out.print("저장할 파일의 이름을 입력하세요...");
ab.save(new String(dis.readLine()));
break;
case 6: //종료하기
iMenu = 6;
break;
default: //잘못된 메뉴가 선택되었을 때
break;
}
}
}catch(IOException ioe){
ioe.printStackTrace();
}
}
}
3. 실행결과 및 설명
전 과제와 실행 결과가 같습니다.
4. 결론
이번 과제는 간단하게 구현할 수 있었습니다. 확실히 직렬화, 역직렬화가 String 방식보다 더 간단한 것 같습니다. 그리고 문서를 바로 열어볼 수 없어서 보안으로 효과도 더 큰 것 같습니다.
  • 가격2,000
  • 페이지수10페이지
  • 등록일2011.08.25
  • 저작시기2011.8
  • 파일형식한글(hwp)
  • 자료번호#697461
본 자료는 최근 2주간 다운받은 회원이 없습니다.
청소해
다운로드 장바구니