> For the complete documentation index, see [llms.txt](https://scls-cs.gitbook.io/scls-apcs-lab/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://scls-cs.gitbook.io/scls-apcs-lab/arraylist-and-2d-array/solution.md).

# Solution

{% code title="Bank.java" %}

```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;
    }
}
```

{% endcode %}

{% code title="Transformation.java" %}

```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;
    }
}
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://scls-cs.gitbook.io/scls-apcs-lab/arraylist-and-2d-array/solution.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
