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();

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

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
Transcribed Image Text: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
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
Transcribed Image Text: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
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY