I am new to java trying to complete an introductory course and am really struggling. I have included the code I believe should be working but when i run the test they fail and return null. can anyone help to see what is wrong with my code? thank you so much
public class CustomString {
String myString;
boolean isSet;
public CustomString() {
this.myString = (null);
this.isSet = (false);
}
}
if the string hasn't been set with setString it should return null. setString should set the value of the current string and set this.isSet to true. and if the given string is null, sets this.isSet to false
public String getString() {
if (this.myString == null || this.isSet == false) {
return null;
} else {
return this.myString;
}
}
public void setString(String string) {
if (this.myString == null) {
this.isSet = false;
} else {
this.isSet = true;
}
}