어제 지식인 질문 올라온 것 추가질문을 예상해서 미리 만들어 둔건데..

답변의 의견란에 기존 질문에서 추가 된 내용이 있길래, 먼저 채택하고 질문 새로 올리라고 했음.

질문자가 재질문 올리면 바로 등록할려고 만든 건데.. 질문내용이 아래꺼와 달라서 한시간 동안 뻘짓했다.. 쩝..

하지만 그냥 두기 아까워서 여기에 올린다.

 

 

1. CLASS

 

import java.util.Scanner;

 

public class t15_006 {
  public static void main(String arg[]){
    info inf = new info();
    inf.sc = new Scanner(System.in);

 

    while(true){
      System.out.print("1) 입력 | 2) 조회 | 3) 수정 | 4) 전체조회 |  0) 종료 : ");
      String s1 = inf.sc.next();
      inf.sc = new Scanner(System.in);
   
      String name = "";
      String birth = "";
   
      switch(s1){
        case "1" : 
          String no = info.getCount() + "";
     
          System.out.print("- " + info.getCount() + "번) 사람의 이름을 입력 : ");
          name = inf.sc.next();
    
          System.out.print("- " + info.getCount() + "번) 사람의 생일을 입력 : ");
          birth = inf.sc.next();
    
          inf.ifo(no, name, birth);
          break;
    
        case "2" :
          System.out.print("조회할 내용을 입력  1) 이름 | 2) 생일 : ");
          String selm = inf.sc.next();
    
          if(selm.equals("1")) {
            System.out.print("- 조회할 사람의 이름를 입력 : ");
            String pno = inf.sc.next();
            inf.sfo(pno, 1);


          } else if(selm.equals("2")) {
            System.out.print("- 조회할 사람의 생일을 입력 : ");
            String pno = inf.sc.next();
            inf.sfo(pno, 2);


          } else {
            System.out.println("- 1), 2) 중에서 선택!!");
          }
          break;
    
        case "3" :
          System.out.print("수정할 번호를 입력 : ");
          String msel = inf.sc.next();
    
          if(inf.sfo(msel, 0) == true){
            System.out.print("\n- 수정할 이름을 입력 : ");
            name = inf.sc.next();
            // System.out.println("수정 : " + name);
     
            System.out.print("- 수정할 생일을 입력 : ");
            birth = inf.sc.next();
     
            inf.mfo(msel, name, birth);
          }
          break;
    
        case "4" :
          inf.ofo();
          break;

 

        case "0" :
          System.out.println("프로그램 종료!!");
          return;
    
        default :
          System.out.println("잘못된 입력!!");
      }
      System.out.println();
    }
  }
}

 

class info{
  Scanner sc = null;
  static String info[][] = new String[100][3];
  private static int count = 1;
 
  void ifo(String a, String b, String c){  // 1) 입력
    info[getCount()][0] = a;
    info[getCount()][1] = b;
    info[getCount()][2] = c;
    count++;
  }
 
  boolean sfo(String no, int sel){  // 2) 조회
    // System.out.println(count + " / " + no + " / " + sel);
    int cot = 0;
  
    System.out.println("\n번호 \t 이름 \t 생일");
    System.out.println("--------------------------");


    for(int i = 1; i < getCount(); i++){
      if(info[i][sel].equals(no) ){
        System.out.printf("%s \t %s \t %s \n", info[i][0], info[i][1], info[i][2]);
        cot++;
      }
    }
  
    if(cot == 0){
      System.out.println("조회된 결과가 없습니다.");
      return false;
    }
    return true;
  }
 
  void mfo(String no, String name, String birth){ // 3) 수정
    for(int i = 1; i < getCount(); i++){
      if(info[i][0].equals(no) ){
        if(name != null) info[i][1] = name;
        if(birth != null) info[i][2] = birth;
      }
    }
  }
 
  void ofo(){  // 4) 전체 조회
    int cot = 0;  
    System.out.println("\n번호 \t 이름 \t 생일");


    for(int i = 0; i < getCount(); i++){
      if(info[i][0] != null){
        System.out.printf("%s \t %s \t %s \n", info[i][0], info[i][1], info[i][2]);
        cot++;
      }else{
        System.out.println("--------------------------");
      }
    }
  
    if(cot == 0) System.out.println("등록된 사람이 없습니다.");
  }

 

  public static int getCount() {
    return count;
  }

}

 

 

 

2. RUN

 

 

 

 

 

// 이정도면 대학생들 리포트 제출용으로 딱!! 이겠구만..