디시인사이드 갤러리

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

갤러리 본문 영역

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

햐...(112.163) 2011.11.06 11:55:30
조회 70 추천 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 - -
이슈 [디시人터뷰] 충무로가 주목하는 신예, '세계의 주인' 서수빈 운영자 25/11/24 - -
AD 대학생 필수템! What's in my Bag 운영자 25/11/21 - -
286281 여자들한테 결혼상대로 프로그래머는 어떻게 보일까? [4] 설치마법사갤로그로 이동합니다. 11.11.06 162 0
286280 흔한 겜돌이의 스펙 [6] 햏햏했갤로그로 이동합니다. 11.11.06 269 0
286279 밑에 짤린 face mash 글 잘만드셨네요 ^_^. 그리고 재밌었음 [1] Stan(220.244) 11.11.06 54 0
286278 아 슬프다 페이스매쉬 글짤렸네 [4] 늅늅(203.250) 11.11.06 87 0
286277 횽들.. 웹에서 정보가져올려면 뭘 알아야되? [3] 흠좀무(59.31) 11.11.06 59 0
286275 최종학력이 중요한거 아닌가? [13] 전간디갤로그로 이동합니다. 11.11.06 246 0
286272 학부 2학년 전공스펙 평가점 [26] 지잡거지(122.32) 11.11.06 322 0
286270 Will code for food. 1(121.182) 11.11.06 95 0
286269 학부생(2학년)C언어 공부 테크트리 알려준다. [8] ㄹㄹㄷ(14.32) 11.11.06 301 0
286268 형님들 이게 무슨말인지 잘모르겠어요 C언어 [2] ㅠㅠ(211.246) 11.11.06 84 0
286267 java 문자열 비교에 관한 질문이에요 [3] 최강전설그녀갤로그로 이동합니다. 11.11.06 106 0
286266 웹프로그래밍 어떤언어로 하는게 제일 실행속도 빠르냐? [4] 정수정•‿•갤로그로 이동합니다. 11.11.06 123 0
286265 http request를 socket의 send로 보내려하는데 어케하죠? [1] 듣보잉여(123.109) 11.11.06 46 0
286264 프로그래머하다 때려치면 닭집사장말고 피씨방 사장도되냐? [3] ekrclrhwjdcl갤로그로 이동합니다. 11.11.06 154 0
286263 니들 아이패드용 브라더 인 암스할 때 조심해라 분당살람갤로그로 이동합니다. 11.11.06 51 0
286260 형들 제가 c++ 한권을 끝냈습니다 [4] ㄱㄱ(223.222) 11.11.06 133 0
286259 형들 나누기를 비트 연산으로 하려면 어떻게 해야할까? [4] 회색사과갤로그로 이동합니다. 11.11.06 150 0
286256 아침부터 숙제글 ㅋㅋ 열심히 하시네 [2] [성대아싸]갤로그로 이동합니다. 11.11.06 78 0
286255 진짜 모르겠어요 이거좀 짜주세요 [2] 길동홀(175.125) 11.11.06 93 0
자바 코딩중 질문입니다..(질문 수정) [3] 햐...(112.163) 11.11.06 70 0
286253 구문이해가 안된다 치킨맛맛폰갤로그로 이동합니다. 11.11.06 59 0
286252 C언어좀 도와주세요 [1] 길동홀(175.125) 11.11.06 66 0
286249 활기찬 아침 프갤러들을 위한 은꼬리^^ [5] 얼빠진호랑이갤로그로 이동합니다. 11.11.06 155 0
286248 그러고 보니까 집에 핸드폰 놓고왔네 얼빠진호랑이갤로그로 이동합니다. 11.11.06 49 0
286247 학원에 일빠로 도착했다 얼빠진호랑이갤로그로 이동합니다. 11.11.06 76 0
286246 니들이라면 150만원으로 맥북에어삼? [9] 선행자갤로그로 이동합니다. 11.11.06 281 0
286245 야 c언어 맛야 [4] Adelposs갤로그로 이동합니다. 11.11.06 98 0
286244 늅늅이들을 위한 족집게 강좌를 준비했다. [4] 바보플머(59.14) 11.11.06 112 0
286243 형들 용산 캬라멜이나 들어 [3] 버틸수가없ㅋ다갤로그로 이동합니다. 11.11.06 43 0
286242 모레면 소행성이 떨어지는 군화... 거칠게갤로그로 이동합니다. 11.11.06 61 0
286241 미친 디시 어플 패치 좀 ㅡㅡ 거칠게갤로그로 이동합니다. 11.11.06 49 0
286240 일요일 아핌인데 비가 오네염 거칠게갤로그로 이동합니다. 11.11.06 31 0
286236 [ 혐짤 ] 시팔 아파치에 CURL라이브러리 설치해도안됨 [1] 레알폰님갤로그로 이동합니다. 11.11.06 94 0
286234 미쿡인이랑 대화할정도 영어 vs 뛰어난 프로그래밍 실력 [8] 전자후자(220.86) 11.11.06 251 0
286233 형들은 몇살에 졸업후 몇살에첫직장잡음? [1] 三didas갤로그로 이동합니다. 11.11.06 107 0
286232 형드라 생성자에서 객체만들어내거나 머 입력같은 거 받으면 개병신? [4] ^0^갤로그로 이동합니다. 11.11.06 84 0
286230 그니까 그니까 횽 횽 [2] 큐아큐아큥(125.131) 11.11.06 67 0
286229 아어.. ㅠㅜ 형들 다이렉트x 화면에 출력할 전면버퍼나 후면버퍼 [7] 큐아큐아큥(125.131) 11.11.06 79 0
286228 식당 어플을 하나 만들려고 하는데 도움부탁드립니다 [5] 강빛나(117.16) 11.11.06 132 0
286226 asp. php. jsp ? [4] 정승길(116.40) 11.11.06 108 0
286225 쳐 웃은 새끼들은 쥬어없는그분(121.179) 11.11.06 85 0
286224 누가 나를 찐지버거라 칭할수 있는가? 쥬어없는그분(121.179) 11.11.06 75 0
286221 애들아 나 간다 빠이빠이~ 다음 애들 면접 잘 보렴 [1] PoRO갤로그로 이동합니다. 11.11.06 58 0
286220 Daum 면접 3번째인 ㅡㅡ 나로썬 이번에 붙을수밖에없다. [5] 제주도(58.141) 11.11.06 386 0
286219 근데 컬렉션에서 set은 도데체 왜있는건가요? [5] ㅇㅇㅇㅇ(1.212) 11.11.06 78 0
286218 java 능력자 분들 쉬운질문 답변좀 부탁드립니다 [4] java질문人(119.205) 11.11.06 85 0
286217 애 새끼들아 내 이야기 좀 들어봐라 [9] PoRO갤로그로 이동합니다. 11.11.06 155 0
286216 형들, C문법책중에 가장 어려운 책 머가있을까 ?? [4] 늉늉(203.241) 11.11.06 143 0
286215 프로그래밍 선배님들께 진로 조언 부탁드립니다 [15] 컴공(175.193) 11.11.06 190 0
286214 근데 갑자기 안드로이드 궁금한게 [9] 돌아이바갤로그로 이동합니다. 11.11.06 99 0
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

디시미디어

디시이슈

1/2