This may make more sense if I show you a sample run of a program that implements the wizard shown above: Do you want to buy a snowboard? no Do you want to buy downhill skis? yes Have you gone skiing before? yes Are you an expert? no Buy the ZR200 model. Notice how a series of questions is asked by the wizard and answered by the shopper. When there are no more questions to be asked, the conclusion is printed by the wizard and the program exits. The series of questions asked by the wizard closely follows the rules in the flow chart. A Decision object represents a triangle in the flow cart. The Decision object asks a question and then returns either the next decision in the flow chart, or a message that should be printed before the program terminates. This is an example of the Composite design pattern because a Decision object contains other Decision objects. Here is a description of the methods in the IDecision interface: public void setYes(IDecision yes): Specifies the IDecision that should follow this one if the user answers yes to the question. public void setNo(IDecision no): Specifies the IDecision that should follow this one if the user answers no to the question. public void setYesTerminal(String terminal): Specifies the conclusion that will be printed if the user answers yes to the question. public void setNoTerminal(String terminal): Specifies the conclusion that will be printed if the user answers no to the question. public IDecision ask(): This method asks the user the question that was specified when the Decision object was created (using a Scanner object). The return value specifies how we should proceed. If a Decision object is returned then it should be the next question asked. If null is returned, then a conclusion has been printed to the screen, and the line of questioning should stop. The Builder class in the UML diagram is responsible for building the composite of Decision objects. This class should be a singleton. The buildWizard method should construct a collection of interconnected decision objects that represent the flow chart. The first decision in the flow chart should be returned. Now, here are two sample runs that help illustrates how the wizard works: Input entered in the input box: yes yes no Expected output: Do you want to buy a snowboard? Have you snowboarded before? Are you an expert? Buy the XG200 model. Input entered in the input box: no yes yes no Expected output: Do you want to buy a snowboard? Do you want to buy downhill skis? Have you gone skiing before? Are you an expert? Buy the ZR200 model. public class Main { public static void main(String[] args) { IDecision next = Builder.getInstance().buildWizard(); do { next = next.ask(); } while (next != null); } } public interface IDecision { /** * Specifies the IDecision that should follow this one if the user answers yes * to the question. */ public void setYes(IDecision yes); /** * Specifies the IDecision that should follow this one if the user answers no * to the question. */ public void setNo(IDecision no); /** * Specifies the conclusion that will be printed if the user answers yes * to the question. */ public void setYesTerminal(String terminal); /** * Specifies the conclusion that will be printed if the user answers no * to the question. */ public void setNoTerminal(String terminal); /** * Asks the user the question that was specified when the Decision object * was created. The return value specifies how we should proceed. If a * Decision object is returned then it should be the next question asked. If * null is returned then a conclusion has been printed to the screen, and the * line of questioning should stop. */ public IDecision ask();
This may make more sense if I show you a sample run of a program that implements the wizard shown above:
Do you want to buy a snowboard?
no
Do you want to buy downhill skis?
yes
Have you gone skiing before?
yes
Are you an expert?
no
Buy the ZR200 model.
Notice how a series of questions is asked by the wizard and answered by the shopper. When there are no more questions to be asked, the conclusion is printed by the wizard and the program exits. The series of questions asked by the wizard closely follows the rules in the flow chart.
A Decision object represents a triangle in the flow cart. The Decision object asks a question and then returns either the next decision in the flow chart, or a message that should be printed before the program terminates. This is an example of the Composite design pattern because a Decision object contains other Decision objects. Here is a description of the methods in the IDecision interface:
- public void setYes(IDecision yes): Specifies the IDecision that should follow this one if the user answers yes to the question.
- public void setNo(IDecision no): Specifies the IDecision that should follow this one if the user answers no to the question.
- public void setYesTerminal(String terminal): Specifies the conclusion that will be printed if the user answers yes to the question.
- public void setNoTerminal(String terminal): Specifies the conclusion that will be printed if the user answers no to the question.
- public IDecision ask(): This method asks the user the question that was specified when the Decision object was created (using a Scanner object). The return value specifies how we should proceed. If a Decision object is returned then it should be the next question asked. If null is returned, then a conclusion has been printed to the screen, and the line of questioning should stop.
The Builder class in the UML diagram is responsible for building the composite of Decision objects. This class should be a singleton. The buildWizard method should construct a collection of interconnected decision objects that represent the flow chart. The first decision in the flow chart should be returned.
Now, here are two sample runs that help illustrates how the wizard works:
Input entered in the input box:
yes
yes
no
Expected output:
Do you want to buy a snowboard?
Have you snowboarded before?
Are you an expert?
Buy the XG200 model.
Input entered in the input box:
no
yes
yes
no
Expected output:
Do you want to buy a snowboard?
Do you want to buy downhill skis?
Have you gone skiing before?
Are you an expert?
Buy the ZR200 model.
public class Main
{
public static void main(String[] args)
{
IDecision next = Builder.getInstance().buildWizard();
do
{
next = next.ask();
} while (next != null);
}
}
public interface IDecision
{
/**
* Specifies the IDecision that should follow this one if the user answers yes
* to the question.
*/
public void setYes(IDecision yes);
/**
* Specifies the IDecision that should follow this one if the user answers no
* to the question.
*/
public void setNo(IDecision no);
/**
* Specifies the conclusion that will be printed if the user answers yes
* to the question.
*/
public void setYesTerminal(String terminal);
/**
* Specifies the conclusion that will be printed if the user answers no
* to the question.
*/
public void setNoTerminal(String terminal);
/**
* Asks the user the question that was specified when the Decision object
* was created. The return value specifies how we should proceed. If a
* Decision object is returned then it should be the next question asked. If
* null is returned then a conclusion has been printed to the screen, and the
* line of questioning should stop.
*/
public IDecision ask();
}
![untAlg.java - Notepad
it Format View Help
Ln 28, Col 1
100%
Windows (CRLF)
UTF-8
Main
<<<<interface>>>>
IDecision
public void setYes(IDecision yes
public void setNo(IDecision no);
public void setYesTerminal(String terminal);
public void setNOTerminal(String terminal);
public IDecision ask();
<<singleton>>
Builder
public IDecision buildWizard0;
Decision
private String m_question;
private IDecision m_yes;
private IDecision m_no;
private String m_yes Terminal;
private String m_noTerminal;
public void setYes(IDecision yes
public void setNo(IDecision no);
public void setYesTerminal(String terminal);
public void setNo Terminal(String terminal);
public IDecision ask();
1:44 PM
O Type here to search
a
46°F
4/27/2022](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F5b9fc713-35a7-4152-955e-ea0356866640%2F840bd55b-ba44-4a11-8399-1bc44a9c57bc%2Foh4574n_processed.png&w=3840&q=75)
![Main.java - Notepad
ile Edit Format View Help
ublic class Main
Ln 1, Col 1
100%
Unix (LF)
UTF-8
Many online shopping sites now offer you help when you are trying to select a product. These online "wizards" ask you a series of
questions, and based on your answers offer you a product. The following flow chart is an example of a series of questions that an online
"wizard" might use to help a shopper select a new snowboard or pair of skis:
Y
Do you
want to buy a
snowboard?
Have you
snowboarded
before?
Are you
an expert?
Do you like
to go fast?
Buy the XG300
Model.
N
N
Buy the XG100
Model.
Buy the XG200
Model.
N
Y
Do you
want to buy
downhill
skis?
Have you
gone skiing
before?
Are you
an expert?
Do you
like to jump?
Buy the ZR300
Model.
N
Recommend
they try
skiing
someday.
Buy the ZR100
Model.
Buy the ZR200
Model.
IDecision.java - Notepad
ile Edit Format View Help
Ln 1, Col 1
100%
Unix (LF)
UTF-8
10:27 AM
O Type here to search
a
49°F
4/24/2022](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F5b9fc713-35a7-4152-955e-ea0356866640%2F840bd55b-ba44-4a11-8399-1bc44a9c57bc%2Fsv2354q_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)