Search code examples
javamethodsarraylistconstructorrecreate

Recreate ArrayList Methods Error and Constructor Error for Child Class


I have to recreate the arraylist class and I'm having problems with some of the methods. Firstly, I keep getting an error around my .equal method in the FOR loop in the initial IF statement telling me it cannot find the symbol, pointing at the period between getData() and contains. Also when I make my main I'm not sure if I'm supposed to add a constructor, couldn't I somehow use the one from myIntArrayList? I'm having problems with the main not calling on the child class methods. Could you help me with this and are my methods on the right track? He wants us to use the constructors from the parent class but when I use them by making a new object it won't call on the methods in the child class.

public class Project7 extends myIntArrayList{
public int[] copy(myIntArrayList aList){
        int[] temp = new int[aList.size()];
    for(int i =0; i<temp.length;i++){
            temp[i]=aList.getData(i);
        }
        return temp;
}
public boolean equal(myIntArrayList aList){ 
        boolean check = false;
        boolean flag = true;
    if(aList.size() == getData().length){
            while(flag == true){
                for(int i=0;i<getData().length;i++){
                    if(getData().contains(aList.getData(i)))//error
                        check=true;
                    else{
                        check=false;
                        flag=false;
                    }
                }
            }
        }
        else
            check = false;
    return check;   
}
public void congruent(myIntArrayList aList){ //Not Done
    boolean check = false;
        boolean flag = true;
}
public int[] simpleSort(){
    int[] temp = new int[getSize()];
    for(int i=0; i<temp.length;i++){
        temp[i] = getData(i);
    }
    for(int b=1;b<temp.length;b++){
        int a=b;
        while(temp[a-1]>temp[b]){
            temp[a]=temp[a-1];
            a--;
        }
        temp[a]=temp[b];
    }
    return temp;
}
public void bubbleSort(){
    int[] temp = new int[getSize()];
    for(int i=0; i<temp.length;i++){
        temp[i] = getData(i);
    }
    for(int i=0;i<temp.length;i++){
        for(int j=i;j<temp.length;j++){
            if(temp[i]<temp[j]){
                int swap=temp[j];
                temp[j]=temp[i];
                temp[i]=swap;
            }
        }
    }
}
public static void main(String[] args){
    int[] x = new int[6];
    x[0] = 5;
    x[1] = 8;
    x[2] = 3;
    x[3] = 4;
    x[4] = 1;
    x[5] = 9;
    myIntArrayList example = new myIntArrayList(x); //Do i need a Project7 constructor?
    example.print();
    example.bubbleSort();
}

}

Assume all methods and constructors in myIntArrayList work otherwise I can upload to mediafire or post it as well.


Solution

  • When I use the super(); and adding in an array as a parameter I just get "{}" as my output. And the this.length didn't work at all.