I am trying to give a test is that this particular method
public myOwnString changeCase(){
}
This method is trying to return a new myOwnString where the case of each letter is changed to the opposite.
Example
Input : String a = "Hello"
Output : "Hello" -> "hELLO"
This is the code I was thinking it might work for the changeCase() :
if (Character.isUpperCase(a)){
data[i] = Character.toLowerCase(a);
}
else if (Character.isLowerCase(a)){
data[i] = Character.toUpperCase(a);
I understand that the word "Character" is a wrapper class and isnt allow in my coding(google informed unless its wrong). Just needed to find another way without using any of the blacklist, which is String, StringBuilder, or Wrapper classes. The main class isnt suppose to create any string because it is created in the tester class.
I would think I need to use Arrays.toString(), but i would think i have to do it in the beginning of the method before creating the changes.
Main class
public class myOwnString {
//declare the char array
private char data[];
//Main Constructor
public myOwnString(char[] data){
this.data = data;
}
}
public myOwnString changeCase(){
for(int i = 0 ; i < this.data.length ; i++){
char a = this.data[i];
if (Character.isUpperCase(a)){
this.data[i] = Character.toLowerCase(a);
}
else if (Character.isLowerCase(a)){
this.data[i] = Character.toUpperCase(a);
}
}
return new myOwnString(data);
}
}
Test class:
public class testmyOwnString {
public static void main(String[] args) {
String a = "Welcome to this world";
char[] input = a.toCharArray();
myOwnString quote = new myOwnString(input);
System.out.println("The string is : \"" + a + "\"");
System.out.println("\n--------------------------------\n");
System.out.println("To invert the string : " + quote.changeCase());
System.out.println("\n--------------------------------");