2012-12-20 69 views
-1

我無法發送可變餘額和存款以從Driver傳輸到BankAccount,任何人有任何建議嗎?我正在使用BlueJ。將變量發送到不同的類

這裏是驅動器類和方法 -

import javax.swing.JOptionPane; 
public class Driver 
{ 
    int choice; 
    String number; 
    String name; 
    double deposit; 
    double withdraw; 
    double balance; 
    //public Driver() 
    public Driver() 
    { 
     String number = JOptionPane.showInputDialog("1. Deposit 2. Withdraw 3. Balance 4. Change name 5. Exit"); 
     int choice = Integer.parseInt(number); 
     do 
     { 
     if(choice == 1) 
     { 
      String input = JOptionPane.showInputDialog("How much would you like to deposit?"); 
      deposit = Integer.parseInt(input); 
      BankAccount b = new BankAccount(); 
      b.Deposit(); 
      Driver a = new Driver(); 

這裏是的BankAccount計劃專

public class BankAccount 
{ 
double balance = 400; 
double deposit; 
double withdraw; 
double Interest = 1.05; 
String name; 
String accountNumber; 

public double Deposit() 
{ 
    //String input = JOptionPane.showInputDialog("How much would you like to deposit?"); 
    //deposit = Integer.parseInt(input); 
    if (deposit < 10000) 
    { 
     balance = deposit + balance; 

    } 
    return balance; 
} 
+0

您將參數添加到您的存款方法,例如b.Deposit(存款);或者在銀行賬戶類中創建一個構造函數。 – bonCodigo

+0

請注意,您不會將變量發送到類;您通過定義參數來接受另一個變量的值,將它們發送給構造函數或方法。 –

回答

1

你必須有你的depost方法BankAccount類,如下

public double Deposit(double deposit){ 

........... 

} 

和您的雲端硬盤類別應爲

... 
    b.Deposit(deposit); 
... 

方法調用