2014-11-21 26 views
-2

嘿,對不起格式不好。我在一個java類,不知道如何將銀行帳戶數據轉換成一個顯示值的方法,如果有人可以幫助,這將是偉大的!我不明白如何調用相同的方法,但通過不同的銀行帳戶我想我可以直接調用showData(a);但這不起作用。請幫忙!!顯示數據方法

`/** 
* Write a description of class TestBankAccount here. 
* 
* @author (your name) 
* @version (a version number or a date) 
*/ 
import java.util.Scanner; 
public class TestBankAccount 
{ 
    public static void main(String[] args) 
    { 
    int AccountNumber; 
     String name; 
     double balance; 
     double NewBalance; 

     bankAccount newAccount = new bankAccount(); 
     newAccount = getData(newAccount); 



     bankAccount newAccount2 = new bankAccount(); 
     newAccount2 = getData(newAccount); 

     bankAccount newAccount3 = new bankAccount(); 
     newAccount3 = getData(newAccount); 

     bankAccount newAccount4 = new bankAccount(); 

    } 
    public static bankAccount getData(bankAccount s) 
    { 
     int AccountNum; 
     String ownerName; 
     double AccountBalance; 

     Scanner stan = new Scanner(System.in); 
     System.out.print("Enter Account Number "); 
     AccountNum = stan.nextInt(); 
     stan.nextLine(); 
     System.out.print("Enter owner name "); 
     ownerName = stan.nextLine(); 

     System.out.println("Enter Account Balance: "); 
     AccountBalance = stan.nextDouble(); 
     s.setAccountNumber(AccountNum); 
     s.setName(ownerName); 
     s.setBalance(AccountBalance); 
     s.setNewBalance(AccountBalance); 
     return s; 

     } 
     public static void showData(bankAccount a) 
     { 
      System.out.println("The account number is: "); 
     System.out.println(a.getAccountNumber()); 
     System.out.println("The owner name is: "); 
     System.out.println(a.getName()); 
     System.out.println("The balance is: "); 
     System.out.println(a.getNewBalance()); 
     System.out.println(a.explanation());  
    } 
    }`   
+0

請您標點技能的工作。你爲什麼不好格式化,你可以格式化這個帖子?關於你的問題 - 只要仔細看看你的代碼... – home 2014-11-21 16:17:13

+0

我一直在看我的代碼只是請幫助帶領我走向我需要做的事情我很困難。關於格式,我只是非常不熟悉網站,需要幫助很快抱歉! – 2014-11-21 16:23:53

回答

1

你的問題是

bankAccount newAccount = new bankAccount(); 
newAccount = getData(newAccount); 
bankAccount newAccount2 = new bankAccount(); 
newAccount2 = getData(newAccount); 
bankAccount newAccount3 = new bankAccount(); 
newAccount3 = getData(newAccount); 
bankAccount newAccount4 = new bankAccount(); 
newAccount4 = getData(newAccount); 

你總是通過同一個銀行帳戶。在你的方法中,你把所有的東西都設置在那個賬戶上因此這是一個問題。

要麼將​​其更改爲

bankAccount newAccount = new bankAccount(); 
newAccount = getData(newAccount); 
bankAccount newAccount2 = new bankAccount(); 
newAccount2 = getData(newAccount2); 
bankAccount newAccount3 = new bankAccount(); 
newAccount3 = getData(newAccount3); 
bankAccount newAccount4 = new bankAccount(); 
newAccount4 = getData(newAccount4); 

或者改變你的方法在參數用不了。

像這樣:

public static bankAccount getData() 
{ 
    Scanner stan = new Scanner(System.in); 
    bankAccount s = new bankAccount(); 
    System.out.print("Enter Account Number "); 
    s.setAccountNumber(stan.nextInt()); 
    System.out.println("Enter Account Balance: "); 
    As.setBalance(stan.nextDouble()); 
    System.out.print("Enter owner name "); 
    s.setName(stan.nextLine()); 
    return s; 
} 

然後主代碼更改爲:

bankAccount newAccount = getData(); 
bankAccount newAccount2 = getData(); 
bankAccount newAccount3 = getData(); 
bankAccount newAccount4 = getData(); 
+0

謝謝 多 – 2014-11-21 16:50:45