디시인사이드 갤러리

갤러리 이슈박스, 최근방문 갤러리

갤러리 본문 영역

자바로 전화번호부 짰는데 에러가 납니다 도와주세요 ㅠㅠ

ㅇㅇㅇ(211.206) 2010.10.17 02:25:28
조회 119 추천 0 댓글 0


일단 짠 클래스 3개의 소스를 올려 보면,

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

PDApplication.class

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public class PDApplication {
 public static void main(String args[]) {
  if (args.length == 0) {
   System.err.println("You must provide the name of the file"
     + " that contains the phone directory.");
   System.exit(1);
  }
  PhoneDirectory phoneDirectory = new ArrayBasedPD();
  phoneDirectory.loadData(args[0]);
  
  PDUserInterface phoneDirectoryInterface = new PDGUI();
  phoneDirectoryInterface.processCommands(phoneDirectory);
 }

}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

PhoneDirectory.class

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public class ArrayBasedPD implements PhoneDirectory
{
 private static final int INITIAL_CAPACITY = 100;
 private int capacity = INITIAL_CAPACITY;
 private int size = 0;
 
 private DirectoryEntry[] theDirectory =
  new DirectoryEntry[capacity];
 
 private String soureName = null;
 private boolean modified = false;
 
 public void loadData(String sourceName) {
  this.sourceName = sourceName;
  try {
   BufferedReader in = new BufferedReader(new FileReader(sourceName));
   String name;
   String numer;
   while ((name = in.readLine()) != null) {
    if ((number = in.readLine()) == null) {
     break;
    }
    add(name, number);
   }
   in.close();
  }
  catch (FileNotFoundException ex) {
   return;
  }
 }
 public String addOrChangeEntry(String name, String number) {
  String oldNumber = null;
  int index = find(name);
  if (index > -1) {
   oldNumber = theDirectory[index].getNumber();
   theDirectory[index].setNumber(number);
  }
  else {
   add(name, number);
  }
  modified = true;
  return oldNumber;
 }
 public String lookupEntry(String name) {
  int index = find(name);
  if (index > -1) {
   return theDirectory[index].getNumber();
  }
  else {
   return null;
   
  }
 }
 public void save() {
  if (modified) {
   try {
    PrintWriter out = new PrintWriter(new FileWriter(sourceName));
    for (int i = 0; i < size; i++) {
     out.println(theDirectory[i].getName());
     out.println(theDirectory[i].getNumber());   
    }
    out.close();
    modified = false;
   }
   catch (Exception ex) {
    System.err.println("Save of directory failed");
    ex.printStackTrace();
    System.exit(1);
   }
  }
 }
 private int find(String name) {
  for (int i = 0; i < size; i++) {
   if (theDirectory[i].getName().equals(name)) {
    return i;
   }
  }
  return -1;
 }
 
 private void add(String name, String number) {
  if (size >= capacity) {
   reallocate();
  }
  theDirectory[size] = new DirectoryEntry(name, number);
  size++;
 }
 private void reallocate() {
  capacity *= 2;
  DirectoryEntry[] newDirectory = new DirectoryEntry[capacity];
  System.arraycopy(theDirectory, 0, newDirectory, 0,
    theDirectory.length);
  theDirectory = newDirectory;
 }
 
 public String removeEntry(String name) {
 }
}

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

PDGUI.class

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

public class PDGUI implements PDUserInterface {
 private PhoneDirectory theDirectory = null;
 
 public void processCommands(PhoneDirectory thePhoneDirectory) {
  
  String[] commands = {
    "Add/Change Entry",
    "Look Up Entry",
    "Remove Entry",
    "Save Directory",
    "Exit"};
  
  theDirectory = thePhoneDirectory;
  int choice;
  do {
   choice = JOptionPane.showOptionDialog(null, "Select a Command",
     "PhoneDirectory",
     JOptionPane.YES_NO_CANCEL_OPTION,
     JOptionPane.QUESTION_MESSAGE, null,
     commands, commands[commands.length - 1]);
   switch (choice) {
   case 0: doAddChangeEntry(); break;
   case 1: doLookupEntry();    break;
   case 2: doRemoveEntry();    break;
   case 3: doSave();           break;
   case 4: doSave();           break;
   }
  }
  while (choice < commands.length - 1);
  System.exit(0);
 }
 private void doAddChangeEntry() {
  String newName = JOptionPane.showInputDialog("Enter name");
  if (newName == null) {
   return;
  }
  String oldNumber = theDirectory.addOrChangeEntry(newName, newNumber);
  String message = null;
  if (oldNumber == null) {
   message = newName + " was added to the directory"
   + "\\nNew number: " + newNumber;
  }
  else {
   message = "Number for " + newName + " was changed "
   + "\\nOld number: " + oldNumber
   + "\\nNew number: " + newNumber;
  }
  JOptionPane.showMessageDialog(null, message);
 }
 private void doLookupEntry() {
  String theName = JOptionPane.showInputDialog("Enter name");
  if (theName == null) {
   return;
  }
  String theNumber = theDirectory.lookupEntry(theName);
  String message = null;
  if (theNumber != null) {
   message = "The number for " + theName + " is " + theNumber;
  }
  else {
   message = theName + " is not listed in the directory";
  }
  JOptionPane.showMessageDialog(null, message);
 }
 private void doRemoveEntry() {
 }
 private void doSave() {
  theDirectory.save();
 }
}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 

이렇게 3클래스입니다. 소스코드를 보면 여기저기서

 

~~~ cannot be solved to a type 이라는 에러 문구가 뜨네요. 어떻게 해야 좋을까요?

 

도움 좀 부탁드립니다. 해결 할 방법 없나요? 제가 짠 소스는 아니고 그냥 책 같은데에

나와있는데로 그대로 한건데 에러가 나네요 ㅠㅠ 도와주세요

추천 비추천

0

고정닉 0

0

원본 첨부파일 1

댓글 영역

전체 댓글 0
등록순정렬 기준선택
본문 보기

하단 갤러리 리스트 영역

왼쪽 컨텐츠 영역

갤러리 리스트 영역

갤러리 리스트
번호 제목 글쓴이 작성일 조회 추천
설문 연예인 안됐으면 어쩔 뻔, 누가 봐도 천상 연예인은? 운영자 24/06/17 - -
227451 서Xㅇ택 테스트 中 [6] 게임핵(221.162) 10.12.28 87 0
227450 C++ 문제 책 좀 추천해주세요 [3] 척척학사갤로그로 이동합니다. 10.12.28 103 0
227449 만세방학이다!! [3] ㅁㄴㅇㄹ(119.195) 10.12.28 55 0
227448 구글해킹하는거 돠주삼 ㅠ____________ㅠ [6] 게임핵(221.162) 10.12.28 146 0
227447 아 방학 시즌이구나 ㅅㅂ [2] 향균물티슈갤로그로 이동합니다. 10.12.28 39 0
227445 플밍갤왜이럼 ? [4] 향균물티슈갤로그로 이동합니다. 10.12.28 63 0
227443 형들 sprintf가뭐에요?? [4] ㅁㄴㅇㄹ(119.195) 10.12.28 62 0
227442 서든어택 핵쓰는거 프갤러님들이 돠주삼 헤헤헤 *^-------^* [3] 게임핵(221.162) 10.12.28 103 0
227441 순간 여기 프갤 아닌줄 알았다 [1] 르하소갤로그로 이동합니다. 10.12.28 53 0
227440 닉변 짤짤삘라뽕갤로그로 이동합니다. 10.12.28 41 0
227439 님들 서든 핵쓰는거 돠주삼 [3] 게임핵(221.162) 10.12.28 118 0
227436 헤헤 덕짤하면 역시 동방짤 [1] elwlwlwk갤로그로 이동합니다. 10.12.28 76 0
227435 (퍽)이딴것 좀하지말자.... 꿀레갤로그로 이동합니다. 10.12.28 60 0
227434 전자vs후자 [6] 갤러리갤로그로 이동합니다. 10.12.28 139 0
227433 형들헬프!! [2] ㅁㄴㅇㄹ(119.195) 10.12.28 60 0
227432 인천 현재 상황 브리핑 게임핵(221.162) 10.12.28 58 0
227431 덕짤을 싸자 덕짤을 싸자 [4] 땡칠도사갤로그로 이동합니다. 10.12.28 73 0
227430 프갤러님들 저 입갤 ^----^*** [1] 게임핵(221.162) 10.12.28 55 0
227428 아 ㅆㅂ 프갤 글리젠 여전히 빠르네... [4] 삼퀄(125.141) 10.12.28 77 0
227427 아 고3이라 공부해야되는데 [2] 퓨틱갤로그로 이동합니다. 10.12.28 55 0
227426 하지만..답변을안해줘도 프갤러 너흴 이제 미워하지않을게 [2] 게임핵(221.162) 10.12.28 63 0
227425 아 씨발 서울우유치즈 존나 맛없네 ㅠㅠ [2] 게임핵(221.162) 10.12.28 137 0
227424 프겔이 덕갤이 된건 니들이 만들어놓은 허상일뿐 [6] 게임핵(221.162) 10.12.28 92 0
227421 힘든 하루였다 [1] DMW(125.138) 10.12.28 54 0
227420 더블리하면서 생긴 나쁜습관 꿀레갤로그로 이동합니다. 10.12.28 72 0
227419 이거 짜는데 얼마나 걸렷을가여? [3] 갤러리갤로그로 이동합니다. 10.12.28 69 0
227418 VMware 써본 사람들 질문 하나만 합시다 [8] 개르르(164.125) 10.12.27 107 0
227417 솔직히 나도 자바 존나 싫어하지만 [5] 로션맛안심(110.15) 10.12.27 132 0
227416 저새끼자바 게임핵(221.162) 10.12.27 55 0
227415 자바 갤러리 만들어주새여 [10] 갤러리갤로그로 이동합니다. 10.12.27 130 0
227414 핵쓸려는데 [6] 게임핵(221.162) 10.12.27 133 0
227413 형들 제소원 [4] ㅁㄴㅇㄹ(119.195) 10.12.27 90 0
227412 아이유볼때마다 이토준지 만화의 토미에가 생각난다. [2] Finalizer갤로그로 이동합니다. 10.12.27 483 0
227411 답이없군... [2] 꿀레갤로그로 이동합니다. 10.12.27 50 0
227410 나도 빨리나이를먹고싶다. [5] ㅁㄴㅇㄹ(119.195) 10.12.27 104 0
227408 그리고 창업과 사업에 성공할려면 [4] Finalizer갤로그로 이동합니다. 10.12.27 119 0
227406 프갤이 덕화되고있군...이거면 어떠냐!! [3] 꿀레갤로그로 이동합니다. 10.12.27 76 0
227405 char 형 배열마다 루프돌면서 검색하고있는데 검색이안되네영 [17] 준치◕‿◕갤로그로 이동합니다. 10.12.27 110 0
227404 애니갤이라니 [2] 땡칠도사갤로그로 이동합니다. 10.12.27 58 0
227403 솔직히 프겔까지와서 같이 창업할 개발자 모집하려면 [3] Rei@디씨갤로그로 이동합니다. 10.12.27 129 0
227401 완전애니갤만들죠. [1] ㅁㄴㅇㄹ(119.195) 10.12.27 61 0
227400 프갤은 글리젠을 탓하면안된다 ㅇㅇ [3] Grand[차단](221.162) 10.12.27 64 0
227399 나도 한때 소셜거려봤는데 [1] Finalizer갤로그로 이동합니다. 10.12.27 90 0
227397 ㄷㄷ 잘생각해보니 이짤무섭다. [5] ㅁㄴㅇㄹ(119.195) 10.12.27 102 0
227396 질문있어요 횽들~~~~~답변해주면 한국은꼬르가 쏟아짐 [6] Grand[차단](221.162) 10.12.27 76 0
227395 오늘도 잉여의 하루를 보냈네... [7] Rei@디씨갤로그로 이동합니다. 10.12.27 93 0
227394 니들은 현실의 여자도 좋은데 왜 2D로 가려는거냐!! [1] 꿀레갤로그로 이동합니다. 10.12.27 66 0
227393 같이 할 프로그래머 모집! [8] thegle(58.141) 10.12.27 179 0
227392 근디 보통 이짝 일하는 사람들은 메카덕후 아닙미까??? [9] 시불라미갤로그로 이동합니다. 10.12.27 114 0
227391 나 별명이 은꼬르인데 조공주면 포인터 답해주나여??? [2] Grand[차단](221.162) 10.12.27 127 0
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

뉴스

디시미디어

디시이슈

1/2