2012-10-06 2 views
0

저는 Java로 프로젝트를하고 있는데, 그 부분에 붙어 있습니다. 예금 기능이 SavingsAccount 클래스에서 작동하지만 엔진 클래스에서 호출하는 방법을 알아낼 수 없습니다. 우리 프로젝트에서 BlueJ 가상 머신을 사용하여 사용자가 여러 은행 계좌를 만들고 그 사이에 자금을 이체 할 수 있도록해야합니다. 내 엔진 클래스와 저축 예금 클래스에 대한 관련 코드를 게시 할 예정입니다 ... 감사합니다. 도움을 주시면 감사하겠습니다!은행 계좌 이관 프로젝트 Java

문제점 : 한 계좌에서 다른 계좌로 송금 할 수 없는데 엔진 클래스에 오류 메시지가 표시됩니다. 나는

저축 계정 코드

public class SavingsAccount extends BankAccount 
public void transfer (BankAccount that, double amount) 
{ 
    if 
    (balance-amount < -80) 
    balance = balance ; 
    else 
    { 
     if 
     (amount <= balance) 
      { 
       this.balance = this.balance - amount; 
       that.balance = that.balance + amount; 
      } 
     else 
      { 
       this.balance = this.balance - amount-20; 
       that.balance = that.balance + amount; 
      } 
    } 
} 

엔진 클래스

public class engine 
{ 
SavingsAccount savings1 = new SavingsAccount(); 
savings1.balance = 0; 

//code for other choices, such as deposit and withdraw... 

    if (selection2 == 3) 
     { 
      System.out.println ("How much would you like to transfer?"); 
      int transferAmount = in.nextInt (); 
      System.out.println ("Which account would you like to transfer the money to?"); 
      String thatAccount = in.next(); 
      savings1.withdraw (transferAmount); 
      thatAccount.deposit (transferAmount); 
      System.out.println ("You account balance is " + savings1.getBalance() + "!"); 

     } 
+0

나는 당신의 질문을 undestand하지 않습니다. –

+5

지금까지 무엇을하고 있는지, 돈이 어디에 포함되어 있는지 이중으로 사용해서는 안됩니다. 대신 BigDecimal을 사용하십시오. –

+0

한 계좌에서 다른 계좌로 돈을 송금 할 수 없으며 엔진 클래스에서 오류가 발생합니다. 나는 내가 돈을 보내고있는 계좌로 뭔가 잘못하고 있다고 생각한다. – user1691618

답변

3

내가 가진 일부에게 ... 내가 돈을 보내고있다 계정으로 뭔가 잘못하고 있다고 생각 obervation/suggestions below :

귀하의 이전 계좌는 thatAccount입니다. 문자열 String thatAccount = in.next();. 그걸 어떻게 deposit() 전화 할 수 있습니까?

SavingsAccount 클래스에 deposit()withdraw() 메서드가 표시되지 않으며, BankAccount 클래스에 존재할 수 있기를 바랍니다.

잔액 초기화 방법은 saving1.balance=0;입니다. 예를 들어, 클래스 메소드를 통해 수행되어야합니다. setBalancesaving1.setBalance(0);입니다.

savings1.withdraw() 메서드를 호출 할 때 잔액은 0입니다.

희망 사항은 문제를 확인하고 프로그램을 수정하는 데 도움이되기를 바랍니다.

+0

내가 도움이 필요한 것 . 사용자가 선택한 전송 대상을 어떻게 찾을 수 있습니까? 지금 당장은 문자열 일 뿐이라는 것을 알지만, 그 시점에서 무엇을해야할지 모르겠습니다. Java에서 매우 제한된 경험이 있습니다. – user1691618

+1

잘 모르겠습니다. 얼마나 도움이 될 수 있지만 엔진 클래스의 기본 단계를 따라야합니다. 1. 맵을 Map maintainAccounts = new HashMap ();'로 정의하십시오. 2. 계정을 인스턴스화하고 맵에'maintainAccounts.put ("acountNumber123", savings1);'을 입력하십시오. 3.'withdraw' 또는'depost' 전에 은행 계좌를'SavingsAccount accountToMaintain = maintainedAccounts.get ("accountNumber123");'으로하십시오. 4. 검색된 뱅크 객체에서 원하는 기능을 호출합니다. 'accountToMaintain.deposit (1000); 또는'accountToMaintain.withdraw (500);' –

관련 문제