Answered step by step
Verified Expert Solution
Question
1 Approved Answer
A A checker is an object that examines strings and accepts those strings that meet a particular public In this question, you will write two
A
A checker is an object that examines strings and accepts those strings that meet a particular
public
In this question, you will write two classes that extend the Checker class. You will then create a Checker object that checks for a particular acceptance criterion.
a A substringChecker accepts any String that contains a particular substring. For example, the following substringChecker object broccolichecker accepts al Checker broccolichecker new
Checker broccolichecker new SubstringCheckerbroccoli;
The following table illustrates the results of several calls to the broccolichecker's accept method.
Result
tablebroccolicheckeracceptbroccolitruebroccoliCheckeracceptI like broccoli"truebroccoliCheckeracceptcarrots are great"falsebroccoliCheckeracceptBroccoli Bonanza"false
Write the SubstringChecker class that extends the checker class. The constructor should take a single String parameter that represents the particular substring to be matched.
b Checkers can be created to check for multiple acceptance criteria by combining other checker objects. For example, an AndChecker is a Checker that is constructed with or AndChecker objects The AndChecker's accept method returns true if and only if the String is accepted by both of the Checker objects with which it was In the code segment below, the bothChecker object accepts all strings containing both "beets" and "carrots". The code segment also shows how the veggies object "carrots", and "artichokes" Checker bchecker new subs
Checker bChecker new SubstringChecker beets; Checker bothcher new SubstringChecker carrots
Checker achecker new Substrinecker bChecker cChecker; Checker veggies new AndCheckerbothChecker aChecker; The following table illustrates the results of several calls to the accept method using bothchecker and veggies. Method Call
Result
tableMethod Call,ResultbothCheckeraccept I love beets and carrots"truebothCheckeracceptbeets are great"falseveggiesacceptartichokes beets, and carrots"true
Write the AndChecker class that extends the Checker class. The constructor should take two Checker parameters.
c Another subclass of the Checker class is the NotChecker, which contains the following:
A oneparameter constructor that takes one Checker object accept the String
Using any of the classes SubstringChecker, AndChecker, and NotChecker, construct a Checker that accepts a String if and only if it contains neither the Checker to yummychecker.
Consider the following incomplete code segment.
Checker achecker new Substringcheckerartichokes;
Checker kChecker new SubstringChecker kale; Checker yummyChecker;
I code to construct and assign to yummychecker
The following table illustrates the results of calls to the yummychecker's accept method.
tableMethod Call,ResultyummyCheckeraccept chocolate truffles"trueyummyCheckeracceptkale is great"falseyummyCheckeracceptYuck: artichokes & kale"false
In writing your solution, you may use any of the classes specified for this problem. Assume that these classes work as specified, regardless of what you wrote in parts a and b You may assume that the declarations for aChecker, kChecker, and yummyChecker in the code segment above have already been executed.
Write your code to construct and assign to yummychecker below.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started