*q4: Write a public class named Final with the following *-A public constructor
ID: 3732236 • Letter: #
Question
*q4: Write a public class named Final with the following *-A public constructor that takes 4 Strings. The Strings should be stored in instance *-A public method named replaceChar that takes no parameters and has return type void. This method removes all instances of the character 'b' from the instance variable storing the * String that was the second parameter in the constructor call *-An overridden toString method that returns the stored strings separated by spaces. This * includes all the Strings from the constructor call and if replaceChar was called on this instance then the second String will not contain any instances of 'bExplanation / Answer
public class Final {
String a, b, c, d;
Final(String a, String b, String c, String d) {
this.a = a;
this.b = b;
this.c = c;
this.d = d;
}
void replaceChar() {
String res = "";
for (int i = 0; i < b.length(); ++i) {
if (b.charAt(i) != 'b')
res = res + b.charAt(i);
}
b = res;
}
public String toString() {
return a + " " + b + " " + c + " " + d;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.