디시인사이드 갤러리

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

갤러리 본문 영역

자바 코딩중 질문입니다..(질문 수정)

햐...(112.163) 2011.11.06 11:55:30
조회 72 추천 0 댓글 3

import java.util.Scanner;

class UserInfo {
 String year = "0", month = "0", date = "0", money = "0", contents = "0";

 public UserInfo(String year, String month, String date, String money,
   String contents) {
  this.year = year;
  this.month = month;
  this.date = date;
  this.money = money;
  this.contents = contents;
 }

 public void showUserInfo() {
  System.out.print("년 : " + year + "    월 : " + month + "    일 : " + date
    + "    금액 : " + money + "    내용 : " + contents);
  System.out.println();
 }
}

class baseData {
 String y="0", m="0", d="0", mon="0";

 public baseData(String y, String m, String d, String mon) {
  this.m = m;
  this.d = d;
  this.mon = mon;
 }
 public void showbaseData() {
  System.out.print("년 : " + y + "    월 : " + m + "    일 : " + d + "    금액 : " + mon);
  System.out.println();
 }
}

class inputData {
 static final int MAX_CNT = 100;
 static UserInfo[] user1 = new UserInfo[MAX_CNT]; // 배열 선언
 static baseData[] base = new baseData[MAX_CNT];

 static int curCnt = 0;
 int baseCnt = 0;
 int count;
 
 public void inputData() {
  System.out.println("데이터 입력을 시작합니다..");
  System.out.print("년 : ");
  String year = MenuViewer.keyboard.nextLine();
  System.out.print("월 : ");
  String month = MenuViewer.keyboard.nextLine();
  System.out.print("일 : ");
  String date = MenuViewer.keyboard.nextLine();
  System.out.print("금액 : ");
  String money = MenuViewer.keyboard.nextLine();
  System.out.print("내용 : ");
  String contents = MenuViewer.keyboard.nextLine();
  user1[curCnt++] = new UserInfo(year, month, date, money, contents);
  System.out.println("데이터 입력이 완료되었습니다. \\n");
 }
}

class Change extends inputData {

 public void searchData() {
  System.out.println("데이터 검색을 시작합니다..");
  System.out.print("년 : ");
  String searchYear = MenuViewer.keyboard.nextLine();
  System.out.print("월 : ");
  String searchMonth = MenuViewer.keyboard.nextLine();
  System.out.print("일 : ");
  String searchDate = MenuViewer.keyboard.nextLine();

  int dataIdx = search(searchYear, searchMonth, searchDate);
  if (dataIdx < 0) {
   System.out.println("해당하는 데이터가 존재하지 않습니다. \\n");
  } else {
   user1[dataIdx].showUserInfo();
   System.out.println("데이터 검색이 완료되었습니다. \\n");
  }
 }

 public void printData() {
  for (int dataIdx = 0; dataIdx < curCnt; dataIdx++) {
   user1[dataIdx].showUserInfo();
  }
  System.out.println("데이터 출력이 완료되었습니다. \\n");
 }

 public void changeData() {
  int spendMoney = 0;
  int saveMoney = 0;
  String updateMoney;
  int a;
  int Money;
  int choice;
  System.out.println("데이터 입력을 시작합니다..");
  System.out.println("1. 수입");
  System.out.println("2. 지출");
  choice = MenuViewer.keyboard.nextInt();
  MenuViewer.keyboard.nextLine();

  if (choice == 1) {// 더하기
   System.out.print("년 : ");
   String year = MenuViewer.keyboard.nextLine();
   System.out.print("월 : ");
   String month = MenuViewer.keyboard.nextLine();
   System.out.print("일 : ");
   String date = MenuViewer.keyboard.nextLine();
   System.out.print("금액 : ");
   String money = MenuViewer.keyboard.nextLine();
   System.out.print("내용 : ");
   String contents = MenuViewer.keyboard.nextLine();
   System.out.print("이프전");
   if (baseCnt >0) {
    System.out.print("첫이프 125");
    for (int baseCnti = 0; baseCnti < curCnt; baseCnti++) {
     System.out.print("포 127");
     if (base[baseCnti].y == year && base[baseCnti].m == month && base[baseCnti].d == date) {
      System.out.print("두번째 이프 129");
      saveMoney = Integer.parseInt(money);
      Money = Integer.parseInt(base[curCnt].mon);
      a = Money + saveMoney;
      updateMoney = Integer.toString(a);
      user1[curCnt++] = new UserInfo(year, month, date, updateMoney, contents);
      base[curCnt++] = new baseData(year, month, date, money);
     } else {
      System.out.print("엘스 137");
      user1[curCnt++] = new UserInfo(year, month, date, money, contents);// 기준이 없을때는 그냥 들어감(입력된게 기준에 저장)
      base[curCnt++] = new baseData(year, month, date, money);
     }
    }
   } else {
    System.out.print("아래엘스 143");
    user1[curCnt++] = new UserInfo(year, month, date, money, contents);// 기준이 없을때는 그냥 들어감(입력된게 기준에 저장)
    base[curCnt++] = new baseData(year, month, date, money);
    
   }
   System.out.println("데이터 입력이 완료되었습니다.");
  }
 }

 public void deleteData() {
  System.out.println("데이터 삭제를 시작합니다..");

  System.out.print("년 : ");
  String year = MenuViewer.keyboard.nextLine();
  System.out.print("월 : ");
  String month = MenuViewer.keyboard.nextLine();
  System.out.print("일 : ");
  String date = MenuViewer.keyboard.nextLine();

  int dataIdx = search(year, month, date);
  if (dataIdx < 0) {
   System.out.println("해당하는 데이터가 존재하지 않습니다. \\n");
  } else {
   for (int idx = dataIdx; idx < (curCnt - 1); idx++)
    user1[idx] = user1[idx + 1];

   curCnt--;
   System.out.println("데이터 삭제가 완료되었습니다. \\n");
  }
 }

 private int search(String year, String month, String date) {
  for (int idx = 0; idx < curCnt; idx++) {
   UserInfo curInfo = user1[idx];
   if (year.compareTo(curInfo.year) == 0
     & month.compareTo(curInfo.month) == 0
     & date.compareTo(curInfo.date) == 0)
    return idx;
  }
  return -1;
 }
}

class MenuViewer {
 public static Scanner keyboard = new Scanner(System.in);

 public static void showMenu() {
  System.out.println("금전 출납 관리 프로그램 입니다.");
  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.print("선택: ");
 }
}

class MoneyManage2 {
 public static void main(String[] args) {
  Change change = new Change();

  int choice;

  while (true) {
   MenuViewer.showMenu();
   choice = MenuViewer.keyboard.nextInt();
   MenuViewer.keyboard.nextLine();

   switch (choice) {
   case 1:
    change.inputData();
    break;
   case 2:
    change.searchData();
    break;
   case 3:
    change.printData();
    break;
   case 4:
    change.changeData();
    break;
   case 5:
    change.deleteData();
    break;
   case 6:
    System.out.println("프로그램을 종료합니다");
    return;
   }
  }
 }
}

추천 비추천

0

고정닉 0

0

댓글 영역

전체 댓글 0
본문 보기

하단 갤러리 리스트 영역

왼쪽 컨텐츠 영역

갤러리 리스트 영역

갤러리 리스트
번호 제목 글쓴이 작성일 조회 추천
설문 뛰어난 운동 신경으로 남자와 싸워도 이길 것 같은 여자 스타는? 운영자 25/11/24 - -
AD 따뜻한 겨울나기! 방한용품 SALE 운영자 25/11/27 - -
286706 단기간에 토익 점수 끌어올리기 비법 있음?? [4] [성대아싸]갤로그로 이동합니다. 11.11.07 291 0
286705 저기 형들 씨쁠쁠 프로그래밍 하나만 도와줘 [4] 김역태(61.79) 11.11.07 59 0
286704 형들 c아주 기초 질문좀.. [4] ㆍ엘마갤로그로 이동합니다. 11.11.07 66 0
286703 SuCo 비트 수료생으로써 하나 조언하자면 [5] 버틸수가없ㅋ다갤로그로 이동합니다. 11.11.07 135 0
286700 보쌈 먹고싶다 [1] ㄱㄴㄴ(218.153) 11.11.07 28 0
286699 근데 쌍용이나 비트나 [5] 막장갤신학생갤로그로 이동합니다. 11.11.07 272 0
286698 SuCo 비트컴 학생이라 이거지? [9] 버틸수가없ㅋ다갤로그로 이동합니다. 11.11.07 131 0
286697 면접 볼 때, 존나 당황되지 않냐? [4] ㅇㅇ(121.133) 11.11.07 147 0
286696 배우는것 보다 가르치는것이 어렵네요 ㅠㅠ [2] 막장갤신학생갤로그로 이동합니다. 11.11.07 44 0
286695 지구에서 30년 살아보고 내린 결론 [3] 분당살람갤로그로 이동합니다. 11.11.07 90 0
286693 신입사원이 여직원이라면.. [1] 허공갤로그로 이동합니다. 11.11.07 93 0
286691 다음이 구글한테 먹히면 이렇게되는건가? 557갤로그로 이동합니다. 11.11.07 66 0
286690 허공형 안드로이드 10만 다운인데 그리 좆망? [1] 안드러이드(125.133) 11.11.07 55 0
286689 실근무지에서 숭실대 컴학이 그렇게 많어? [1] 라차차(115.90) 11.11.07 150 0
286688 성대아싸횽 언제옴여 [1] SuCo갤로그로 이동합니다. 11.11.07 55 0
286686 밤늦게 뭐 먹지마세여 [4] SuCo갤로그로 이동합니다. 11.11.07 80 0
286685 R-basic 언어는 무슨 언어냐 [2] ㅈㅈㅈㅈ(118.47) 11.11.07 79 0
286684 푸갤정모중 [1] 꼬꼬월드갤로그로 이동합니다. 11.11.07 60 0
286683 wwww 봐라 [1] Blazer사마갤로그로 이동합니다. 11.11.07 35 0
286682 윈7폰 vs 아이폰 어떤게 경쟁력있냐? [4] 허공갤로그로 이동합니다. 11.11.07 83 0
286681 야 요즘에 daum 장사 잘 안되냐? [5] 1(121.182) 11.11.07 98 0
286680 나 군대가기 전에 육개월 닭튀겻는데 [2] 돌아이바갤로그로 이동합니다. 11.11.07 71 0
286679 내가 그리 권했던 샘숭 지원한 횽들 있냐??? 거칠게갤로그로 이동합니다. 11.11.07 59 0
286678 아이폰 어플은 맥으로만 제작가능? [1] 557갤로그로 이동합니다. 11.11.07 51 0
286677 제군들이여 지금이 기회다 얼렁 SM엔터테이먼트로 출동하자!! [1] 거칠게갤로그로 이동합니다. 11.11.07 67 0
286676 데스크젯횽. gdb는 있는데 이거 이클립스랑 연동 못해? Blazer사마갤로그로 이동합니다. 11.11.07 45 0
286675 이거 자바 좀 실행되게 해줄사람.. [7] ㅈㅈㅈㅈ(118.47) 11.11.07 74 0
286674 내 신상을 파해치는 세력이 있어.. [5] SuCo갤로그로 이동합니다. 11.11.07 99 0
286672 아우 진짜 저밑에 도그테이프글 너무 웃긴다ㅋㅋ Stan(220.244) 11.11.07 46 0
286671 난 굳센남자다 Adelposs갤로그로 이동합니다. 11.11.07 31 0
286670 이런 사이트 아는형님 ?? [1] 츄젹방지(121.134) 11.11.07 54 0
286669 아 존니 이쁘네 ㅡㅡ 쌀거같다 [1] SuCo갤로그로 이동합니다. 11.11.07 126 0
286667 나무심는다는게 [1] Adelposs갤로그로 이동합니다. 11.11.07 52 0
286666 스크립트 편집하기 편한 프리웨어 없나요 ㅠㅠㅠ [4] 123(121.144) 11.11.07 65 0
286665 앜!!!!!!!!!!!!! 셐스하고싶다 셐스!!!!!!!!!!!꺄악! Stan(220.244) 11.11.07 64 0
286664 내일 멸망할지도 모르는데 다들 나무는 심고 있냐??? [1] 거칠게갤로그로 이동합니다. 11.11.07 63 0
286662 이클립스로 C개발환경 만들어쓰는사람 있나여? [2] Blazer사마갤로그로 이동합니다. 11.11.07 82 0
286661 안드로이드 애니메이션 만드는 어플 만들라고 하는데 [1] 갤럭시s갤로그로 이동합니다. 11.11.07 210 0
286660 지구 멸망전 직접 그린 그림 몇점 공개 [1] Stan(220.244) 11.11.07 99 0
286659 지금내얼굴이 내가 전생에 가장 사랑했던사람 얼굴이래 [2] 중간점검갤로그로 이동합니다. 11.11.07 62 0
286658 안드로이드 좀 해본 사람 있음? [1] ㅇㅇㅁㅇㄻㅁ갤로그로 이동합니다. 11.11.07 60 0
286657 아아 이제 목숨이 하루도 안남았구나... [2] 거칠게갤로그로 이동합니다. 11.11.07 86 0
286656 요즘 시대는 프로그래머가 대우 좀 받나여?? 거칠게갤로그로 이동합니다. 11.11.07 72 0
286655 자바 함수 선언 질문좀 [3] ㅈㅈㅈㅈ(118.47) 11.11.07 232 0
286654 여직원 셋이상 있는 회사 가면 둘중 하나를 택해라. [2] 고기BASIC(58.122) 11.11.07 141 0
286653 8 시 넘어서 면접 제의 오는 회사는 뭐냐 거칠게갤로그로 이동합니다. 11.11.07 82 0
286652 홈페이지 만들 때요 도그테이프 퍼블릭 있잖아요.. 개드립(218.147) 11.11.07 67 0
286651 케이 앱스 전망은 어케 생각하심 [1] [성대아싸]갤로그로 이동합니다. 11.11.07 94 0
286649 Stan님 2차원 배열 개념 자체가 헷갈리고 있습니다 ㅠㅠ [9] 치킨맛맛폰갤로그로 이동합니다. 11.11.07 97 0
286646 수치해석 파워메소드 소스좀 ㅜㅜ 살고싶다 ㅈㅈㅈㅈ(118.47) 11.11.07 42 0
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

디시미디어

디시이슈

1/2