类型不兼容-无法将储蓄帐户转换为帐户,JNI错误

时间:2018-11-25 11:23:54

标签: java

我在帐户[0]到3处收到此错误。我也收到JNI错误,请检查您的安装并重试。任何人都可以为我解决此问题提供任何见解。

公共抽象类Account1 {

    private int id;
    double balance;

    public Account1() {
       // TODO Auto-generated constructor stub

       this.balance = 0;

    }

    /**
    * @param id
    * @param balance
    */
    public Account1(int id, double balance) {
       this.id = id;
       this.balance = balance;
    }

    /**
    * @return the id
    */
    public int getId() {
       return id;
    }

    /**
    * @return the balance
    */
    public double getBalance() {
       return balance;
    }

    /**
    * @param id
    * the id to set
    */
    public void setId(int id) {
       this.id = id;
    }

    /**
    * @param balance
     * the balance to set
    */
    public void setBalance(double balance) {
       this.balance = balance;
    }

   /**
   * @param amount
   */
   public void deposit(double amount) {
       try {

           if (amount < 0)
               throw new IllegalAmountException();

           else
               this.balance += amount;

       } catch (IllegalAmountException e) {
           // TODO: handle exception
           e.printStackTrace();
       }

   }

   public abstract void withdraw(double amount);

   public String toString() {
       return "Account [id=" + id + ", balance=" + balance + "]";
   }

    private static class IllegalAmountException extends Exception {

        public IllegalAmountException() {
        }
    }

public static void main(String[] args) {

       try {
           Account[] accounts = new Account[4];

           accounts[0] = new CheckingAccount(1111, 2340);
           accounts[1] = new CheckingAccount(1112, 200);
           accounts[2] = new SavingsAccount(1113, 700);
           accounts[3] = new SavingsAccount(1114, 900);

           System.out.println("Initial Acounts:");
           for (int i = 0; i < accounts.length; i++) {
               System.out.println(accounts[i].toString());
           }

           System.out.println("Initial Acounts: ");
           for (int i = 0; i < accounts.length; i++) {
               System.out.println(" " + accounts[i].toString());
           }

           System.out.println("After deposit 500 to Acounts: ");
           for (int i = 0; i < accounts.length; i++) {
               accounts[i].deposit(500);
               System.out.println(" " + accounts[i].toString());
           }

           System.out.println("After withdraw 200 to Acounts: ");
           for (int i = 0; i < accounts.length; i++) {
               accounts[i].withdraw(200);
               System.out.println(" " + accounts[i].toString());
           }

           System.out.println("Checking Withdraw from Insufficient balance: ");
           accounts[1].withdraw(700);

           System.out.println("Checking deposit with negative amount: ");
           accounts[1].deposit(-700);

       } catch (Exception e) {
           // TODO: handle exception
       }

   }

    private static class Account {

        public Account() {
        }

        private void deposit(int i) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        private void withdraw(int i) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    }
}

我在帐户[0]到3处收到此错误。我也收到JNI错误,请检查您的安装并重试。任何人都可以为我解决此问题提供任何见解。

0 个答案:

没有答案