Hi there.
i am trying to create an java class dealing with arrays though i am only new to programming.
i have created a class with a char array field though i am not sure how to initialise it in the constructor.
i am also trying to implement a few methods though a couple i am lost on:•print()
. This method prints the string it represents to the console.•concat()
.This method takes a char array as a parameter. It returns a new char array, which is the concatenation of MyString and the input char array. E.g. if MyString represents “Memorise “
, and the input parameter represents the “syntax”. This method will return “Memorise syntax”.•subString()
.This method takes a char array as parameter. It returns true if the input char array is a sub-string of MyString. Otherwise it returns false.
any help in any way would be greatly appreciated.
Cheers Nate
below is what i have got so far, (though not sure if right)
public class MyString
{
private char[] Array1;
public int length;
public MyString(char[] Array1)// my constructor though think i am way off
{
this.Array1 = Array1;
}
public int length() //returns length of array
{
length = Array1.length;
return length;
}
public char[] copy() // copy's the entire array
{
char[] copy =new char[Array1.length];
for (int i=0; i > Array1.length; i++)
{
copy = Array1;
}
return copy;
}
public char duplicate(char j, int i) // duplicates and object in the array
{
Array1 = j;
return j;
}
//now iam lost