Please write in JAVA ONLY Write an object class with just on
Please write in JAVA ONLY!
Write an object class with just one instance variable, an integer array. Your constructor should take an integer array as its only parameter.
Write all the accessors, mutators, toString and equals methods.
Also write an additional RECURSIVE method that returns the sum of all the elements in the array (your method should have an array as it\'s argument and should have the recursive call in its return for the general case).
Write a client class to test all your methods and especially your recursive method.
Solution
public class Object
{
private int[] a;
Object(){a=null;}
Object(int[] a)
{
this.a=a;
}
public void setA(int[] a)
{
this.a=a;
}
public getA()
{
return this.a;
}
public String toString()
{
return a.toString();
}
public boolean equals(Object O)
{
if(this.a.length==this.O.length&&this.a==O.a)
return true;
return false;
}
public int sum(int[] a,int n)//call with n equals zero
{
if(n<=a.length())
return a[n]+sum(a,n++);
else return;
}
}

