2016-11-19 11 views
-1

Max & Minアカウントも印刷する方法を理解しようとしていますが、アカウント番号、残高、平均取引金額が印刷されます。アレイリスト平均

私はあらゆる種類の服を試しましたが、どこにもいませんでした。

import java.util.ArrayList; 
import java.util.Scanner; 

public class BankAccount { 


    private int AccountNumber; 
    public int getAccountNumber() 
    { 
     return AccountNumber; 
    } 

    private double Balance; 
    public double getBalance() 
    { 
     return Balance; 
    } 

    private ArrayList<Double> transactions = new ArrayList<Double>(); 

    public void Deposit(double Balance) 
    { 
     transactions.add(Balance); 
     this.Balance = this.Balance + Balance; 
    } 

    public void Withdraw(double Balance) 
    { 
     transactions.add(-Balance); 
     this.Balance = this.Balance - Balance; 
    } 

    public BankAccount(int initialAccountNumber, double initialBalance) 
    { 
     this.Balance = initialBalance; 
     this.AccountNumber = initialAccountNumber; 
     transactions.add(initialBalance); 
    } 

    public double getAverage() 
    { 
     double sum = 0; 
     for (double element : transactions) 
     { 
      sum = sum + Math.abs(element); 
     } 

     double Average = sum/transactions.size(); 
     return Average; 
    } 

    } 


--- 

    import java.util.ArrayList; 

    public class Bank { 

     private ArrayList<BankAccount> accounts = new ArrayList<BankAccount>(); 


     public void MakeAccount(int initialAccountNumber, double initialBalance) 
     { 
      BankAccount NewAcc = new BankAccount(initialAccountNumber, initialBalance); 
      accounts.add(NewAcc); 
     } 


     public BankAccount FindLarAcc(int initialAccountNumber, double initialBalance) 
     { 
      BankAccount largest = accounts.get(0); 

      for (int i = 1; i < accounts.size(); i++) 
      { 
       BankAccount a = accounts.get(i); 
       if (a.getBalance() > largest.getBalance()) 
        largest = a; 
      } 
      return largest; 
        } 


     public BankAccount FindLowAcc(int initialAccountNumber, double initialBalance) 
     { 
      BankAccount smallest = accounts.get(0); 

      for (int i = 1; i < accounts.size(); i++) 
      { 
       BankAccount a = accounts.get(i); 
       if (a.getBalance() < smallest.getBalance()) 
        smallest = a; 
      } 
      return smallest; 
        } 

     public BankAccount FindAcc(int initialAccountNumber) 
     { 
      for (BankAccount a: accounts) 
      { 
       if (a.getAccountNumber() == initialAccountNumber) 
        return a; 
      } 
      return null; 
     } 

    } 


--- 

    import java.util.Scanner; 

    public class BankTester { 

    public static void main(String[] args){ 

    Scanner in = new Scanner (System.in); 
    /**int AccountNumber = 0;*/ 
    double Balance = 0; 
    double Amount = 0; 

    Bank Bank1 = new Bank(); 


    boolean done = false; 
    while (!done) 
    { 
     System.out.println("Enter an Account Number to begin, enter -1 to quit: "); 
     int AccountNumber = in.nextInt(); 
     if (AccountNumber == -1) 
     { 
      done = true; 
     } else { 

      System.out.println("Now enter a Balance: "); 
      Balance = in.nextDouble(); 
      Bank1.MakeAccount(AccountNumber, Balance); 
      BankAccount B = Bank1.FindAcc(AccountNumber); 

      System.out.println("How much would you like to deposit? "); 
      Amount = in.nextDouble(); 
      B.Deposit(Amount); 

      System.out.println("How much would you like to withdrawl? "); 
      Amount = in.nextDouble(); 
      B.Withdraw(Amount); 


     } 



     BankAccount Max = Bank1.FindLarAcc(AccountNumber, Balance); 
     BankAccount Min = Bank1.FindLowAcc(AccountNumber, Balance); 

     /** 
     * Print & Compute Average 
     */ 


     System.out.println("Account " + Min.getAccountNumber() +      
       " has the smallest balance. "); 

     System.out.println("Account " + Max.getAccountNumber() + 
       " has the largest balance. "); 




     } 

    } 

} 
+0

は常にあなたのプログラミング言語にタグを付け、BankTesterクラスに属します。これはおそらくあなたがこの投稿に最小限の意見を持っている理由です –

答えて

0

同じ問題を抱えている可能性のある人には...私はそれを理解しました。

これはところで

System.out.println("Account " + Min.getAccountNumber() +      
      " has the smallest balance of, " + Min.getBalance() + 
      " and a average transaction of, " + Min.getAverage()); 


    System.out.println("Account " + Max.getAccountNumber() + 
      " has the largest balance of, " + Max.getBalance() + 
      " and a average transaction of, " + Max.getAverage());