Answered step by step
Verified Expert Solution
Link Copied!

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 SubstringChecker("broccoli");
The following table illustrates the results of several calls to the broccolichecker's accept method.
Result
\table[[broccolichecker.accept("broccoli"),true],[broccoliChecker.accept("I like broccoli"),true],[broccoliChecker.accept("carrots are great"),false],[broccoliChecker.accept("Broccoli 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 AndChecker(bothChecker, aChecker); The following table illustrates the results of several calls to the accept method using bothchecker and veggies. Method Call
Result
\table[[Method Call,Result],[bothChecker.accept ("I love beets and carrots"),true],[bothChecker.accept("beets are great"),false],[veggies.accept("artichokes, 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 one-parameter 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 Substringchecker("artichokes");
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.
\table[[Method Call,Result],[yummyChecker.accept ("chocolate truffles"),true],[yummyChecker.accept("kale is great"),false],[yummyChecker.accept("Yuck: 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.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analysis Using SQL And Excel

Authors: Gordon S Linoff

2nd Edition

111902143X, 9781119021438

More Books

Students also viewed these Databases questions