자바 맵 컬렉션으로 간단한 전화번호부 프로그램만들기

lfs의 이미지

import java.lang.*;
import java.io.*;
import java.util.*;
 
public class phone{
    public static void main(String[] args) throws Exception{
        Telman tel=new Telman();
 
        while(true){
            tel.menu();
 
            InputStream is=System.in;
            Reader reader=new InputStreamReader(is);
            BufferedReader br=new BufferedReader(reader);
            char No=(char)br.read();
 
            if(No=='1') tel.input();
            else if(No=='2') tel.output();
            else if(No=='3') tel.modify();
            else if(No=='4') tel.del();
            else if(No=='5') tel.search();
            else if(No=='6') tel.help();
            else if(No=='7') break;
            else continue;
 
        }
    }
}
 
class Telman{
    Map<String,String> map=new Hashtable<String,String>();
    Scanner scanner=new Scanner(System.in);
 
    public void menu() throws Exception{
        System.out.printf("┌────────┐\n");
        System.out.printf("│   1.번호 입력  │\n");
        System.out.printf("│   2.번호 출력  │\n");
        System.out.printf("│   3.번호 수정  │\n");
        System.out.printf("│   4.번호 삭제  │\n");
        System.out.printf("│   5.번호 검색  │\n");
        System.out.printf("│   6.도 움  말  │\n");
        System.out.printf("│   7.종     료  │\n");
        System.out.printf("└────────┘\n");
        System.out.printf(" 입력>>");
    }
 
    public void input() throws Exception{
 
 
        System.out.print("이름:");
        String nameData=scanner.nextLine();
        System.out.print("전화번호:");
        String telData=scanner.nextLine();
 
        map.put(nameData,telData);
 
    }
 
    public void output() throws Exception{
        Set<String> keySet=map.keySet();
        Iterator<String> keyIterator=keySet.iterator();
        while(keyIterator.hasNext()){
            String nameData=keyIterator.next();
            String telData=map.get(nameData);
            System.out.println(nameData+"\t"+telData);
        }
        System.out.println();
    }
 
    public void modify() throws Exception{
        System.out.print("번호변경이름입력:");
        String MnameData=scanner.nextLine();
        System.out.print("변경전화번호입력:");
        String MtelData=scanner.nextLine();
        map.put(MnameData,MtelData);
        System.out.println("변경되었습니다.");
    }
 
    public void del() throws Exception{
        System.out.print("삭제할이름입력:");
        String DnameData=scanner.nextLine();
        map.remove(DnameData);
        System.out.println("삭제되었습니다.");
    }
 
    public void search() throws Exception{
        System.out.print("검색할이름입력:");
        String SnameData=scanner.nextLine();
 
        if(map.containsKey(SnameData)){
            System.out.println(SnameData+"\t"+map.get(SnameData));
            System.out.println("검색되었습니다.");
        }
    }
 
    public void help() throws Exception{
        System.out.println("검색수정삭제는 이름을입력하세요.");
        System.out.println("사용해주셔서 감사합니다.");
    }
}

자바 맵 컬렉션으로 간단하게 전화번호부 프로그램을 만들었습니다.
이상입니다.

Forums: 
lfs의 이미지

댓글 초보입니다.

세벌의 이미지

소스코드 들여쓰기 반영되게 하려면 아래 링크 참고
https://kldp.org/node/158191