디시인사이드 갤러리

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

갤러리 본문 영역

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

ㅇㅇㅇ(211.206) 2010.10.17 02:25:28
조회 118 추천 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/10 - -
225522 횽들 visual c++ 파일 열기 하니깐 메모리를 참조 할 수 업다? [6] 123(114.206) 10.12.17 109 0
225521 팩알고리즘 짜봤음 [2] elwlwlwk갤로그로 이동합니다. 10.12.17 113 0
225518 math.h에 거듭제곱 함수 있나요? [5] elwlwlwk갤로그로 이동합니다. 10.12.17 191 0
225517 원래 언어는 기계어 부터 배워야 되는건데 [9] 홍어(58.180) 10.12.17 204 0
225516 도와줘~!~ [5] 잡대생(218.50) 10.12.17 73 0
225515 할껀많은데 심심하다.. [4] 꿀레갤로그로 이동합니다. 10.12.17 120 0
225514 아 나는 머리가 돌인가 -_-;; 방향 좀... [1] 썬잡아갤로그로 이동합니다. 10.12.17 104 0
225513 ↓지뢰지대 삼치맛우유(110.15) 10.12.17 50 0
225512 하악하악 아이유 [4] 유리한갤로그로 이동합니다. 10.12.17 174 0
225511 CRC 코드 아는 님들 있나요???? [3] fdfd(119.196) 10.12.17 255 0
225509 초짜에겐 10000! 프로그램이 너무 어렵습네다 [1] 컴맹늅늅이(121.135) 10.12.17 120 0
225506 그깟 irc밴당했다고 아쉬워 할필요없음 [1] 르하소갤로그로 이동합니다. 10.12.17 107 0
225503 스마트폰을 위한 무선충전 시스템 같은거 가능하냐? [3] 홍어(58.180) 10.12.17 73 0
225501 버스안에서 자다가 정류장 지나침ㅠ- 꿀레갤로그로 이동합니다. 10.12.17 72 0
225498 2000만 팩 [1] 이단아갤로그로 이동합니다. 10.12.17 89 0
225493 오브ㅈㅌㅂ씨 진짜 초보임.. ㅠㅠ 도와주셈 ㅠㅠ [3] fdfd(119.196) 10.12.17 56 0
225492 방학때 공수나 파야지 [4] 이단아갤로그로 이동합니다. 10.12.17 87 0
225491 아 휘밤 방금 종나 엄청난 사업아이디어가 떠올랐다. [2] 홍어(58.180) 10.12.17 112 0
225489 그리드 팩토리얼 구현해봐. 홍어(58.180) 10.12.17 81 0
225488 니네 내가 누군지 모르나본데, [3] new gay[max](183.105) 10.12.17 116 0
225486 야 요즘엔 멀티코어가 일반화되었는데 팩떡밥도 진화되야지 [5] 홍어(58.180) 10.12.17 102 0
225485 프로그래머 수준별 팩토리얼 프로그램 짜는법은 어떨까? [5] 컴맹늅늅이(121.135) 10.12.17 173 0
225483 c에서 1000000! 출력하려면 자료형이 뭐여야되죠??? [12] 컴돌이(58.77) 10.12.17 213 0
225482 소프트웨어 갤이랑 프갤이랑 뭔차이임? [4] SebasT갤로그로 이동합니다. 10.12.17 127 0
225481 인셉션을 봤는데 이해 안되는점 Vita500갤로그로 이동합니다. 10.12.17 162 0
225479 신종플루의 위엄 nRST갤로그로 이동합니다. 10.12.17 63 0
225478 아주아슬횽은 봅니다. [4] Vita500갤로그로 이동합니다. 10.12.17 116 0
225477 ㅋㅋㅋ iljeomobolt갤로그로 이동합니다. 10.12.17 57 0
225474 아 답없다... [2] 지화자(221.148) 10.12.17 91 0
225472 난 소심해서 이런생각듬.. [3] 꿀레갤로그로 이동합니다. 10.12.17 79 0
225470 열도의 기타연주.. [1] rntjr(121.190) 10.12.17 108 0
225468 시간이 빨리간다 [2] 유리한갤로그로 이동합니다. 10.12.17 159 0
225464 왜 나는 100만 팩토리얼 구하는데 4분이 걸리지; [4] fp빠돌이갤로그로 이동합니다. 10.12.17 205 0
225463 먼가요 1.5v 신나게 깟더니 [6] 이단아갤로그로 이동합니다. 10.12.17 132 0
225462 폭행녀 마음도 이해가 된다. [4] 꿀레갤로그로 이동합니다. 10.12.17 135 0
225461 북적거리는 프로그래밍 관련 사이트가 없어서 슬푸다. [5] BTTTS!갤로그로 이동합니다. 10.12.17 129 0
225457 C++ 언어 using std::cout 이거 뭐죠 [3] (118.36) 10.12.17 150 0
225456 안드로이드 Cursor 개념좀 쎄워종~~ 징징~ [5] 홍어(58.180) 10.12.17 514 0
225455 워 시발 존나 시껍했음 -_- [5] 아주아슬갤로그로 이동합니다. 10.12.17 169 0
225454 이아저씨 아는분??? [5] iljeomobolt갤로그로 이동합니다. 10.12.17 110 0
225453 이거 실용신안등록할생각인데 어때? [11] BTTTS!갤로그로 이동합니다. 10.12.17 182 0
225452 컴퓨터언어는 언어에 가까울까요 수학에 가까울까요??? [3] 컴돌이(58.77) 10.12.17 139 0
225451 혹시 나는 위대한 해커가 되겠다 생각하면서 잡은횽있음? 컴맹늅늅이(121.135) 10.12.17 64 0
225450 제발 살려주세요 부탁드려요 [2] 제발부탁해요갤로그로 이동합니다. 10.12.17 64 0
225449 다이어트엔 잠이 최고다. [6] 홍어(58.180) 10.12.17 94 0
225447 안영기님의 또다른 지식의 성전이 파스칼로 짠거라길래 [5] 컴맹늅늅이(121.135) 10.12.17 130 0
225446 알바 오늘 출근 안했겠지? [2] rntlr(121.182) 10.12.17 77 0
225445 Minryu 언니는 봅니다. [1] iljeomobolt갤로그로 이동합니다. 10.12.17 126 0
225444 이 소스좀 봐줘봐 그딴건없구염'ㅡ'갤로그로 이동합니다. 10.12.17 140 0
225443 구석에서 막 뛰어나온 일점오볼트라고 합니다. [5] iljeomobolt갤로그로 이동합니다. 10.12.17 116 0
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

뉴스

디시미디어

디시이슈

1/2