Java 将变量发送到其他类

Java 将变量发送到其他类,java,class,variables,bluej,Java,Class,Variables,Bluej,我无法将可变余额和存款从司机转移到银行账户,有人有什么建议吗?我用的是BlueJ 下面是驱动程序类和方法- import javax.swing.JOptionPane; public class Driver { int choice; String number; String name; double deposit; double withdraw; double balance; //public Driver()

我无法将可变余额和存款从司机转移到银行账户,有人有什么建议吗?我用的是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();
这是银行账户计划-

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;
}
公共类银行账户
{
双倍余额=400;
双重存款;
双退;
双倍利息=1.05;
字符串名;
字符串accountNumber;
公众双重存款()
{
//String input=JOptionPane.showInputDialog(“您想存多少?”);
//存款=整数.parseInt(输入);
如果(存款<10000)
{
余额=存款+余额;
}
收益余额;
}

您必须在
银行账户
类中使用depost方法,如下所示

public double Deposit(double deposit){

...........

}
你的驾驶等级应该是

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

方法调用

将参数添加到存款方法中,例如b.deposit(存款);或在银行帐户类中创建构造函数。请注意,您不向类发送变量;您可以通过定义参数来接受另一个变量的值,从而将变量发送给构造函数或方法。