자바 가계부 질문
글쓴이: onerat / 작성시간: 수, 2018/09/26 - 8:46오후
자바 가계부에서 managemnet 클래스를 만들었습니다.
여기서 문제점은 다른 컴퓨터에서는 잘 돌아가던 것이 다음과 같은 오류가 납니다.
1. 48번과 70번 줄의 'a'에서 Activity[]->int 변경 불가
2. 60번과 82번 줄에서 'searchIn(after.getDate())', 'searchOut(after.getDate())' 리턴 타입을 int로 변경
어떻게 해결하면 좋을까요..?ㅠㅡㅠ 제발 도와주세요..
management 클래스는 다음과 같습니다
import java.util.GregorianCalendar;
public class Management {
Activity infoIncome[] = new Activity[50]; // 수입 정보 객체를 담을 배열
Activity infoOutcome[] = new Activity[50]; // 지출 정보 객체를 담을 배열
private int balance; // 잔액
private int indexIn = 0; // 수입 배열의 방의 번호
private int indexOut = 0; // 지출 배열의 방의 번호
// 수입
public void insertIn(Activity acin) throws Exception {
// 에러와 수입입력을 실행하는 insertIn 함수
if(indexIn == infoIncome.length) {
// 배열이 꽉 찼을 때 에러
throw new Exception("\n내용이 들어갈 자리가 없습니다.\n");
}
// 수입 입력
infoIncome[indexIn] = acin; // acin값을 수입 배열의 방 번호 하나하나에 넣어주기
indexIn++; // 방 번호는 자동으로 0, 1, 2번 ...
balance += acin.getMoney(); // 수입 balance 돈 쌓임
}
// 지출
public void insertOut(Activity acout) throws Exception {
// 에러와 지출 입력을 실행하는 insertOut 함수
if(indexOut == infoOutcome.length) {
// 배열이 꽉 찼을 때 에러
throw new Exception("\n내용이 들어갈 자리가 없습니다.\n");
}
// 지출 입력
infoOutcome[indexOut] = acout; // acout값을 지출 배열의 방 번호 하나하나에 넣어주기
indexOut++; // 방 번호는 자동으로 0, 1, 2번 ...
balance -= acout.getMoney(); // 지출 balance 돈 빠짐
}
public Activity[] deleteIn(GregorianCalendar someDay) throws Exception{
// 수입 삭제
Activity[] a = searchIn(someDay);
if(a != null){
for(int j = a; j<indexIn-1; j++)
infoIncome[j] = infoIncome[j+1]; // 찾은 이름 방에 다음 방을 넣기
indexIn--;
}
else
throw new Exception("해당 회원이 없습니다");
}
public void updateIn(Activity before, Activity after) throws Exception{
// 수입 수정
Activity[] a = searchIn(after.getDate());
if(a == null){
infoIncome[searchIn(after.getDate())] = before ;
}
else
throw new Exception("update 할 수 없습니다.");
}
public Activity[] deleteOut(GregorianCalendar someDay) throws Exception{
// 지출 삭제
Activity[] a = searchOut(someDay);
if(a != null){
for(int j = a; j<indexOut-1; j++)
infoOutcome[j] = infoOutcome[j+1]; // 찾은 이름 방에 다음 방을 넣기
indexOut--;
}
else
throw new Exception("해당 회원이 없습니다");
}
public void updateOut(Activity before, Activity after) throws Exception{
// 지출 수정
Activity[] a = searchOut(after.getDate());
if(a == null){
infoOutcome[searchOut(after.getDate())] = before ;
}
else
throw new Exception("update 할 수 없습니다.");
}
// 수입 검색
public Activity[] searchIn(GregorianCalendar someDay) throws Exception{
Activity[] searchArr = new Activity[indexIn];
int count=0;
for(int i=0; i<indexIn; i++) {
if(infoIncome[i].getDate().equals(someDay))
searchArr[count++] = infoIncome[i];
}
return searchArr;
}
//지출검색
public Activity[] searchOut(GregorianCalendar someDay) throws Exception{
Activity[] searchArr = new Activity[indexOut];
int count=0;
for(int i=0; i<indexOut; i++) {
if(infoOutcome[i].getDate().equals(someDay))
searchArr[count++] = infoOutcome[i];
}
return searchArr;
}
// 수입 일정 기간 검색
public Activity[] searchIn(GregorianCalendar fromDay, GregorianCalendar toDay) throws Exception{
Activity[] searchArr = new Activity[indexIn];
int count =0;
for(int i=0; i<indexIn; i++) {
if((infoIncome[i].getDate().compareTo(fromDay)>=0)&&(toDay.compareTo(infoIncome[i].getDate())>=0))
searchArr[count++] = infoIncome[i];
}
return searchArr;
}
// 지출 일정 기간 검색
public Activity[] searchOut(GregorianCalendar fromDay, GregorianCalendar toDay) throws Exception{
Activity[] searchArr = new Activity[indexOut];
int count =0;
for(int i=0; i<indexOut; i++) {
if((infoOutcome[i].getDate().compareTo(fromDay)>=0)&&(toDay.compareTo(infoOutcome[i].getDate())>=0))
searchArr[count++] = infoOutcome[i];
}
return searchArr;
}
public void setBalance(int amount) { //보호되었던 balance 잔액을 외부로 사용 가능
// 잔액 설정
balance = amount;
}
public int getBalance() { //보호되었던 balace 잔액을 외부로 사용 가능
// 잔액 받아오기
return balance;
}
// 수입 출력 함수
public String toStringIn(int index) {
return ("날짜: " + infoIncome<ol>
</ol>
.getDate().get(GregorianCalendar.YEAR) + "년"
+ infoIncome<ol>
</ol>
.getDate().get((GregorianCalendar.MONTH)+1) + "월"
+ infoIncome<ol>
</ol>
.getDate().get(GregorianCalendar.DAY_OF_YEAR) + "일"+
"\n항목 : " + infoIncome<ol>
</ol>
.getCategory() +
"\n금액 : " + infoIncome<ol>
</ol>
.getMoney() + "원" +
"\n상세 : " + infoIncome<ol>
</ol>
.getMemo());
}
// 지출 출력 함수
public String toStringOut(int index) {
return ("날짜: " + infoOutcome<ol>
</ol>
.getDate().get(GregorianCalendar.YEAR) + "년"
+ infoOutcome<ol>
</ol>
.getDate().get((GregorianCalendar.MONTH)+1) + "월"
+ infoOutcome<ol>
</ol>
.getDate().get(GregorianCalendar.DAY_OF_YEAR) + "일"+
"\n항목 : " + infoOutcome<ol>
</ol>
.getCategory() +
"\n금액 : " + infoOutcome<ol>
</ol>
.getMoney() + "원" +
"\n상세 : " + infoOutcome<ol>
</ol>
.getMemo());
}
}Forums:


참고해보세요.
일단. 컴파일 되도록 수정은 해봤습니다. ㅇ_ㅇ;;
내용은 좀 더 수정하셔야 할겁니다.
https://ide.goorm.io/
package project; import java.io.*; import java.util.GregorianCalendar; class Activity { private GregorianCalendar m_gc; private int m_money; private int m_index; public void setIndex(int index) { m_index = index; } public void setMoney(int money) { m_money = money; } public void setDate(GregorianCalendar gc) { m_gc = gc; } public int getIndex() { return m_index; } public int getMoney() { return m_money; } public GregorianCalendar getDate() { return m_gc; } public String getCategory() { return ""; } public String getMemo() { return ""; } } public class Main { Activity infoIncome[] = new Activity[50]; // 수입 정보 객체를 담을 배열 Activity infoOutcome[] = new Activity[50]; // 지출 정보 객체를 담을 배열 private int balance; // 잔액 private int indexIn = 0; // 수입 배열의 방의 번호 private int indexOut = 0; // 지출 배열의 방의 번호 //GregorianCalendar //http://jamesdreaming.tistory.com/98 //Convert Current date as integer //https://stackoverflow.com/questions/12067697/convert-current-date-as-integer //Unreported exception java.lang.Exception; must be caught or declared to be thrown [duplicate] //https://stackoverflow.com/questions/37424284/unreported-exception-java-lang-exception-must-be-caught-or-declared-to-be-throw //error: non-static variable this cannot be referenced from a static context //error: unreported exception Exception; must be caught or declared to be thrown public static void main(String[] args) throws Exception { Main m = new Main(); m.fn_start(); } public void fn_start() throws Exception { // { Activity at = new Activity(); at.setMoney(100); at.setDate( new GregorianCalendar(2018,9,26,22,11,00) ); this.insertIn(at); System.out.println("balance : " + balance); } // { Activity at = new Activity(); at.setMoney(100); at.setDate( new GregorianCalendar(2018,9,26,22,11,00) ); insertIn(at); System.out.println("balance : " + balance); } // { Activity at = new Activity(); at.setMoney(50); at.setDate( new GregorianCalendar(2018,9,26,22,11,00) ); insertOut(at); System.out.println("balance : " + balance); } } // 수입 public void insertIn(Activity acin) throws Exception { // 에러와 수입입력을 실행하는 insertIn 함수 if(indexIn == infoIncome.length) { // 배열이 꽉 찼을 때 에러 throw new Exception("\n내용이 들어갈 자리가 없습니다.\n"); } // 수입 입력 infoIncome[indexIn] = acin; // acin값을 수입 배열의 방 번호 하나하나에 넣어주기 indexIn++; // 방 번호는 자동으로 0, 1, 2번 ... balance += acin.getMoney(); // 수입 balance 돈 쌓임 } // 지출 public void insertOut(Activity acout) throws Exception { // 에러와 지출 입력을 실행하는 insertOut 함수 if(indexOut == infoOutcome.length) { // 배열이 꽉 찼을 때 에러 throw new Exception("\n내용이 들어갈 자리가 없습니다.\n"); } // 지출 입력 infoOutcome[indexOut] = acout; // acout값을 지출 배열의 방 번호 하나하나에 넣어주기 indexOut++; // 방 번호는 자동으로 0, 1, 2번 ... balance -= acout.getMoney(); // 지출 balance 돈 빠짐 } public Activity[] deleteIn(GregorianCalendar someDay) throws Exception { // 수입 삭제 Activity[] a = searchIn(someDay); if(a != null) { for(int j = a[0].getIndex(); j<indexIn-1; j++) { infoIncome[j] = infoIncome[j+1]; // 찾은 이름 방에 다음 방을 넣기 indexIn--; } } else { throw new Exception("해당 회원이 없습니다"); } return a; } public void updateIn(Activity before, Activity after) throws Exception { // 수입 수정 Activity[] a = searchIn(after.getDate()); if(a == null) { for(int j = a[0].getIndex(); j<indexIn-1; j++) { infoIncome[j] = before; // 찾은 이름 방에 다음 방을 넣기 } } else { throw new Exception("update 할 수 없습니다."); } } public Activity[] deleteOut(GregorianCalendar someDay) throws Exception { // 지출 삭제 Activity[] a = searchOut(someDay); if(a != null) { for(int j = a[0].getIndex(); j<indexOut-1; j++) { infoOutcome[j] = infoOutcome[j+1]; // 찾은 이름 방에 다음 방을 넣기 indexOut--; } } else { throw new Exception("해당 회원이 없습니다"); } return a; } public void updateOut(Activity before, Activity after) throws Exception { // 지출 수정 Activity[] a = searchOut(after.getDate()); if(a == null) { for(int j = a[0].getIndex(); j<indexIn-1; j++) { infoOutcome[a[j].getIndex()] = before ; } } else { throw new Exception("update 할 수 없습니다."); } } // 수입 검색 public Activity[] searchIn(GregorianCalendar someDay) throws Exception { Activity[] searchArr = new Activity[indexIn]; int count=0; for(int i=0; i<indexIn; i++) { if(infoIncome[i].getDate().equals(someDay)) { searchArr[count] = infoIncome[i]; count++; } } return searchArr; } //지출검색 public Activity[] searchOut(GregorianCalendar someDay) throws Exception { Activity[] searchArr = new Activity[indexOut]; int count=0; for(int i=0; i<indexOut; i++) { if(infoOutcome[i].getDate().equals(someDay)) { searchArr[count] = infoOutcome[i]; count++; } } return searchArr; } // 수입 일정 기간 검색 public Activity[] searchIn(GregorianCalendar fromDay, GregorianCalendar toDay) throws Exception { Activity[] searchArr = new Activity[indexIn]; int count =0; for(int i=0; i<indexIn; i++) { if((infoIncome[i].getDate().compareTo(fromDay)>=0)&&(toDay.compareTo(infoIncome[i].getDate())>=0)) { searchArr[count] = infoIncome[i]; count++; } } return searchArr; } // 지출 일정 기간 검색 public Activity[] searchOut(GregorianCalendar fromDay, GregorianCalendar toDay) throws Exception { Activity[] searchArr = new Activity[indexOut]; int count =0; for(int i=0; i<indexOut; i++) { if((infoOutcome[i].getDate().compareTo(fromDay)>=0)&&(toDay.compareTo(infoOutcome[i].getDate())>=0)) { searchArr[count++] = infoOutcome[i]; } } return searchArr; } public void setBalance(int amount) { //보호되었던 balance 잔액을 외부로 사용 가능 // 잔액 설정 balance = amount; } public int getBalance() { //보호되었던 balace 잔액을 외부로 사용 가능 // 잔액 받아오기 return balance; } // 수입 출력 함수 public String toStringIn(int index) { String str =""; for(int i=0; i<indexIn; i++) { str += "날짜: " + infoIncome[i].getDate().get(GregorianCalendar.YEAR) + "년"; str += infoIncome[i].getDate().get((GregorianCalendar.MONTH)+1) + "월"; str += infoIncome[i].getDate().get(GregorianCalendar.DAY_OF_YEAR) + "일"; str += "\n항목 : " + infoIncome[i].getCategory(); str += "\n금액 : " + infoIncome[i].getMoney() + "원"; str += "\n상세 : " + infoIncome[i].getMemo() + "\n\n"; } return str; } // 지출 출력 함수 public String toStringOut(int index) { String str =""; for(int i=0; i<indexOut; i++) { str += "날짜: " + infoOutcome[i].getDate().get(GregorianCalendar.YEAR) + "년"; str += infoOutcome[i].getDate().get((GregorianCalendar.MONTH)+1) + "월"; str += infoOutcome[i].getDate().get(GregorianCalendar.DAY_OF_YEAR) + "일"+ "\n항목 : " + infoOutcome[i].getCategory(); str += "\n금액 : " + infoOutcome[i].getMoney() + "원" + "\n상세 : " + infoOutcome[i].getMemo() + "\n\n"; } return str; } }----------------------------------------------------------------------------
젊음'은 모든것을 가능하게 만든다.
매일 1억명이 사용하는 프로그램을 함께 만들어보고 싶습니다.
정규 근로 시간을 지키는. 야근 없는 회사와 거래합니다.
각 분야별. 좋은 책'이나 사이트' 블로그' 링크 소개 받습니다. shintx@naver.com
감사합니다:)
감사합니다:)
댓글 달기