Data Structure, HW01

#!! READ THIS !! The following listing is the main class, which should be in the file called Main.java. You have to write your own version of ArrayList that works with this main class. You must not use the arraylist from aj. Somchai's code. (Of course, you can use aj. Somchai code as an example, but do not submit that as your answer).

Please noted that this ArrayList needs only four methods: add, remove, get, size. You don't need to provide everything as in aj. Somchai code.

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
    ArrayList list;
    list = new ArrayList(10);
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter N: ");
    int n = sc.nextInt();
    for (int i = 0; i < n; i++) {
        System.out.println("Enter #" + (i + 1) + ": ");
        int a = sc.nextInt();
        list.add(new Integer(a));
    }

    int command;
    do {
        System.out.println("Enter command: ");
        System.out.println("0: exit");
        System.out.println("1: add");
        System.out.println("2: remove");
        command = sc.nextInt();
        if (command == 1) {
            System.out.println("Enter Value: ");
            int a = sc.nextInt();
            list.add(new Integer(a));
        } else if (command == 2) {
            System.out.println("Enter Value: ");
            int a = sc.nextInt();
            list.remove(new Integer(a));
        }
        for (int i = 0; i < list.size(); i++) {
            System.out.print(" " + list.get(i));
        }
        System.out.println();
    } while (command > 0);
}

}