Description ABString is a class that has one String as an instance variable. isEvenA() returns true if there is an even

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Description ABString is a class that has one String as an instance variable. isEvenA() returns true if there is an even

Post by answerhappygod »

Description
ABString is a class that has one String as an instance
variable.
isEvenA() returns true if there is an even number of 'a' in String,
otherwise false.
Even if there is no 'a' or the String itself is an empty string, it
is considered even. Complete the code in the code template to
produce the given output.
[CONDITIONS]
'recursion' must be used in the process of isEvenA testing.
isEvenA does not have to be called recursively, and if necessary,
another method can be created and used in ABString.
The code given in the code template cannot be changed, only
implementing class ABString is allowed.
Hint
1) As given in the problem, in the case of an empty string,
there are even 'a's.
2) When the first character of String is 'a', the remaining
substring must have an odd number of 'a's so that there are even
number of 'a's overall.
3) When the first character of String is 'a', the remaining
substring must have an even number of 'a's to have an odd number of
'a's overall.
Input
no input
sample output:
code template:
public class Main {
public static void main(String[] args)
{
String str1 =
"abcdaabcdeaba"; // 5 a, odd
String str2 = "";
// 0 a,
even
String str3 = "poaiasdfabaf";
// 4 a, even
String str4 = "ksdflkjlksdf";
// 0 a, even

ABString ab1 = new
ABString(str1);

System.out.println(ab1.isEvenA());

ABString ab2 = new
ABString(str2);

System.out.println(ab2.isEvenA());

ABString ab3 = new
ABString(str3);

System.out.println(ab3.isEvenA());

ABString ab4 = new
ABString(str4);

System.out.println(ab4.isEvenA());

}
}
// your code for class ABString
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply