Solution

Bank.java
import java.util.ArrayList;
public class Bank {
    private ArrayList<Account> accounts;  

    public Bank() {
        accounts = new ArrayList<Account>();
    }

    public void addAccount(Account a) {
        accounts.add(a);
    }
    
    public void printList() {
        for(Account acc: accounts) {
            System.out.println(acc.getName() + " " + acc.getBalance());
        }
    }
    
    public double getTotalBalance() {
        double sum = 0.0;
        for(Account acc: accounts) {
            sum += acc.getBalance();
        }
        return sum;
    }
    
    public int count(double minimum) {
        int cnt = 0;
        for(Account acc: accounts) {
            if(acc.getBalance() >= minimum) cnt++;
        }
        return cnt;
    }
    
    public Account getMaximum() {
        Account a = accounts.get(0);
        for(Account acc: accounts) {
            if(acc.getBalance() >= a.getBalance()) a = acc;
        }
        return a;
    }
}
Transformation.java
public class Transformation {
    public static int[][] trasform(int[][] matrix) {
        int row = matrix.length;
        int col = matrix[0].length;

        int[][] newMatrix = new int[row][col];

        for(int i=0; i<row; i++) {
            for(int j=0; j<col; j++) {
                int x = matrix[i][j];
                if(i == j) {
                    newMatrix[i][j] = x*x;
                } else if((i+j)%2 == 1) {
                    newMatrix[i][j] = -(i+j)*x;
                } else {
                    newMatrix[i][j] = Math.abs((i-j)*x);
                }
            }
        }
        return newMatrix;
    }
    public static int[][] convert(int[][] matrix)  //第一种做法
    {
        int[][] new_matrix=new int[matrix[0].length][matrix.length];
        for(int i=0;i<matrix.length;i++)
        {
            for(int j=0;j<matrix[0].length;j++)
            {
                new_matrix[j][i]=matrix[matrix.length-i-1][j];
            }
        }
        return new_matrix;
    }
    
    public static int[][] convert2(int[][] matrix) { //第二种做法
        int row = matrix.length;
        int col = matrix[0].length;
        int[][] newMatrix = new int[col][row];

        for(int i=0; i<row; i++) {
            for (int j = 0; j < col; j++) {
                newMatrix[j][i] = matrix[i][j];
            }
        }
        for(int i=0; i<newMatrix.length; i++) {
            int start = 0;
            int end = newMatrix[0].length-1;
            while(start < end) {
                int temp = newMatrix[i][start];
                newMatrix[i][start] = newMatrix[i][end];
                newMatrix[i][end] = temp;
                start++;
                end--;
            }
        }
        return newMatrix;
    }
}

Last updated