将变量发送到不同的类

时间:2012-12-20 23:36:06

标签: java class variables bluej

我在发送可变余额和存款以便从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;
}

1 个答案:

答案 0 :(得分:1)

您必须在BankAccount课程中使用您的存款方式,如下所示

public double Deposit(double deposit){

...........

}

并且您的云端硬盘类应为

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

方法调用