2014-11-21 52 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