⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exe5.html

📁 卡耐基课程练习
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<span class="dialogueheader">Take Assessment: Exercise 5</span><br><br>
  <form name="Assm" id="Assm" method="post" action="https://seqcc.icarnegie.com:443/submitassmcmd.php" enctype="multipart/form-data">

<a name="top_of_page"></a><input name="object_id" id="object_id" value="657817" type="hidden"><table><tbody><tr>
  </tr></tbody></table>
<table><tbody><tr>
<td width="5"><br></td>  <td class="td0_instructions" align="left" valign="top">
     <label class="instructions">Please answer the following question(s).<br>
If the assessment includes multiple-choice questions, click the "Submit Answers" button when you have completed those questions.</label></td>
</tr></tbody></table>
<input name="MAX_FILE_SIZE" id="MAX_FILE_SIZE" value="512000" type="hidden"><table><tbody><tr>
<td width="5"><br></td><script language="JavaScript">document.write('<td class=instructions>' + 'You have 120 minutes to take this assessment.' + '<br>' + 'Please complete this assessment by ' + ComputeLocalDate('2008-11-29 10:56:22 UTC') + '.' + '</td>');</script><td class="instructions">You have 120 minutes to take this assessment.<br>Please complete this assessment by Sat Nov 29 2008 18:56:22 GMT+0800.</td>  <td width="5"><br></td></tr></tbody></table>

<a name="top_14555"></a><table><tbody><tr>
<td width="5"><br></td>  <td class="td0_highlight-label" align="right" nowrap="nowrap" valign="top" width="12">
     <label class="highlight-label">1.</label></td>
<td width="5"><br></td>  <td class="td0_x" align="left" valign="top"> <a href="#14555">Go to bottom of question.</a> </td>
</tr></tbody></table>
<table><tbody><tr>
<td width="5"><br></td>  <td class="td0_x" align="left" valign="top"> <!-- new pg 070103 ici --> 
<h2 align="center">Using Design Patterns in the Gourmet Coffee System</h2> 

<h3>Prerequisites, Goals, and Outcomes</h3>
<blockquote> <b><i>Prerequisites:</i></b> Before you begin this exercise, you 
  need mastery of the following: 
  <ul>
    <li> <em>Object-oriented Programming</em>
<ul>
        <li>How to define interfaces</li>
        <li>How to implement interfaces</li>

      </ul>
  </li></ul>
</blockquote>
<blockquote> 
  <ul>
    <li><em>Design Patterns</em>: 
      <ul>
        <li>Knowledge of the singleton pattern</li>
        <li>Knowledge of the strategy pattern</li>

      </ul>
    </li>
  </ul>
  <p> <b><i>Goals:</i></b> Reinforce your ability to use the singleton and strategy 
    patterns
</p><p> <b><i>Outcomes:</i></b> You 
    will demonstrate mastery in the following: 
  </p><ul>
    <li>Producing applications that use the singleton pattern</li>

    <li>Producing applications that use the strategy pattern</li>
  </ul>
</blockquote>
<h3>Background </h3>

<p>In this assignment, you will create another version of the <em>Gourmet Coffee System</em>. This version will  present the user with   four choices:</p>
<blockquote>
  <p>
    <tt>[0] Quit<br>

    [1] Display sales (Plain Text)<br>
    [2] Display sales (HTML)<br>
    [3] Display sales (XML)<br>
    choice&gt;</tt></p>
</blockquote>
<p>The user will be able to display the sales information in three
    formats:
    plain
    text, HTML, or XML. Part of the work has been done for you and is provided
  in the student archive. You will implement the code that formats the
  sales information. This code will use the singleton and strategy patterns. </p>
<h3>Description</h3>

<p>The following class diagram shows how the singleton and strategy pattern will 
  be used in your implementation:</p>
<blockquote> 
  <table border="0" cellpadding="2" cellspacing="2" width="75%">
    <tbody><tr> 
      <td><img src="/content/SSD/SSD3/4.2.0.1/normal/pg-class-imp/pg-adv-clss-dsgn/assm-exer-dsgn-ptrns/pool-pr-dsgn-ptrns/qn-pr-formtr-gou-sys/handout/images/formttr-cof-gou-sys.jpg" alt="Figure 1 Portion of Gourmet Coffee System class diagram" height="426" width="627"></td>
    </tr>
    <tr> 
      <td><strong>Figure 1 </strong><em>Portion of Gourmet Coffee System class diagram</em></td>
    </tr>
  </tbody></table>

</blockquote>
<p>The elements of the pattern are:</p>
<ul>
  <li>Interface <code>SalesFormatter</code> declares a method called <code>formatSales</code> 
    that produces a string representation of the sales information.</li>
  <li>Class <code>PlainTextSalesFormatter</code> implements <code>formatSales</code>. 
    Its version returns the sales information in a plain-text format. </li>

  <li>Class <code>HTMLSalesFormatter</code> implements <code>formatSales</code>. 
    Its version returns the sales information in an HTML format. </li>
  <li>Class <code>XMLSalesFormatter</code> implements <code>formatSales</code>. 
    Its version returns the sales information in an XML format. </li>
  <li>Class <code>GourmetCoffee</code> is the context class. It also contains 
    client code. The client code calls: 
    <ul>

      <li> Method <code>GourmetCoffee.setSalesFormatter</code> to change the 
        current formatter</li>
      <li>Method <code>GourmetCoffee.displaySales</code> to display the sales 
        information using the current formatter</li>
    </ul>
  </li>

</ul>
<p>In this assignment, you should implement the following interface and classes:</p>
<ul>
  <li><code>SalesFormatter</code></li>
  <li><code>PlainTextSalesFormatter</code></li>
  <li><code>HTMLSalesFormatter</code></li>
  <li><code>XMLSalesFormatter</code></li>
  <li><code>GourmetCoffee</code> (a partial implementation is provided in the student archive)</li>

</ul>
<p>Complete implementations of the following classes are provided in the
    student archive:</p>
<ul>
  <li><code>Coffee</code></li>
  <li><code>CoffeeBrewer</code></li>
  <li><code>Product</code></li>
  <li><code>Catalog</code></li>
  <li><code>OrderItem</code></li>

  <li><code>Order</code></li>
  <li><code>Sales</code></li>
</ul>
<h4>Interface <code>SalesFormatter</code></h4>
<p>Interface <code>SalesFormatter</code> declares the method that every "Formatter" 
  class will implement.</p>
<p><em>Method:</em></p>

<ul>
  <li> <code><em>public String formatSales(Sales sales)</em></code>. Produces 
    a string representation of the sales information.</li>
</ul>
<h4>Class <code>PlainTextSalesFormatter</code></h4>
<p>Class <code>PlainTextSalesFormatter</code> implements the interface <code>SalesFormatter</code>. 
  This class is implemented as a singleton so a new object will not be created 
  every time the plain-text format is used.</p>

<p><em>Static variable:</em></p>
<ul>
  <li><code><em>singletonInstance</em></code>. The single instance of class <code></code><code>PlainTextSalesFormatter</code>.</li>
</ul>
<p><em>Constructor and methods:</em></p>
<ul>
  <li> <code><em>static public PlainTextSalesFormatter getSingletonInstance()</em></code>. 
    Static method that obtains the single instance of class <code>PlainTextsalesFormatter</code>. 
  </li>

</ul>
<ul>
  <li> <code><em>private PlainTextSalesFormatter()</em></code>. Constructor that 
    is declared private so it is inaccessible to other classes. A private constructor 
    makes it impossible for any other class to create an instance of class <code>PlainTextSalesFormatter</code>.</li>
</ul>
<ul>
  <li> <code><em>public String formatSales(Sales sales)</em></code>. Produces 
    a string that contains the specified sales information in a plain-text format. 
    Each order in the sales information has the following format: 
    <pre>------------------------
Order <em>number</em>

<em>quantity1</em> <em>code1</em> <em>price1</em>
<em>quantity2</em> <em>code2</em> <em>price2</em>
...
<em>quantityN</em> <em>codeN</em> <em>priceN</em>

Total = <em>totalCost</em></pre>
    where 
    <ul>
      <li><em>number</em> is the order number.</li>
      <li><em>quantityX</em> is the quantity of the product.</li>

      <li><em>codeX</em> is the code of the product.</li>
      <li><em>priceX</em> is the price of the product.</li>
      <li><em>totalCost</em> is the total cost of the order.</li>
    </ul>

    <p>Each order should begin with a dashed line. The first order in the sales 
      information should be given an order number of 1, the second should be given 
      an order number of 2, and so on.</p>
  </li>
</ul>

<h4>Class <code>HTMLSalesFormatter</code></h4>
<p>Class <code>HTMLSalesFormatter</code> implements the interface <code>SalesFormatter</code>. 
  This class is implemented as a singleton so a new object will not be created 
  every time the HTML format is used.</p>

<p><em>Static variable:</em></p>
<ul>
  <li><code><em>singletonInstance</em></code>. The single instance of class <code></code><code>HTMLSalesFormatter</code>.</li>
</ul>
<p><em>Constructor and methods:</em></p>
<ul>
  <li> <code><em>static public HTMLSalesFormatter getSingletonInstance()</em></code>. 
    Static method that obtains the single instance of class <code>HTMLSalesFormatter</code>. 
  </li>

</ul>
<ul>
  <li> <code><em>private HTMLSalesFormatter()</em></code>. Constructor that is 
    declared private so it is inaccessible to other classes. A private constructor 
    makes it impossible for any other class to create an instance of class <code>HTMLSalesFormatter</code>.</li>
</ul>
<ul>
  <li> <code><em>public String formatSales(Sales sales)</em></code>. Produces 
    a string that contains the specified sales information in an HTML format. 
  </li>
</ul>

<blockquote> 
  <ul>
    <li>The string should begin with the following  HTML:    </li>
    <blockquote>
      <pre>&lt;html&gt;
  &lt;body&gt;
    &lt;center&gt;&lt;h2&gt;Orders&lt;/h2&gt;&lt;/center&gt;</pre>

    </blockquote>
    <li>Each order in the sales information should begin with horizontal
      line, that is, an <code>&lt;hr&gt;</code> 
    tag. </li>
    <li>Each order in the sales information should have the following
      format:
    </li>
  </ul>
  <blockquote>
    <pre>    &lt;hr&gt;

    &lt;h4&gt;Total = <em>totalCost</em>&lt;/h4&gt;
      &lt;p&gt;
        &lt;b&gt;code:&lt;/b&gt; <em>code</em>1&lt;br&gt;

        &lt;b&gt;quantity:&lt;/b&gt; <em>quantity</em>1&lt;br&gt;
        &lt;b&gt;price:&lt;/b&gt; <em>price</em>1
     &lt;/p&gt;

	  ...
     &lt;p&gt;
        &lt;b&gt;code:&lt;/b&gt; <em>codeN</em>&lt;br&gt;
        &lt;b&gt;quantity:&lt;/b&gt; <em>quantityN</em>&lt;br&gt;

        &lt;b&gt;price:&lt;/b&gt; <em>priceN</em>
     &lt;/p&gt;</pre>
    <p> where:</p>
  </blockquote>
  <ul>

    <ul>
      <li><em>quantityX</em> is the quantity of
        the product.</li>
      <li><em>codeX</em> is the code of the product.</li>
      <li><em>priceX</em> is the  price of the product.</li>

      <li><em>totalCost</em> is the total cost of the order.</li>
    </ul>
  </ul>
  <ul>
    <li>The string should end with the following HTML: 
      <blockquote>
        <pre>  &lt;/body&gt;<br>&lt;/html&gt;</pre>

      </blockquote>
    </li>
  </ul>
</blockquote>

<h4>Class <code>XMLSalesFormatter</code></h4>
<p>Class <code>XMLSalesFormatter</code> implements the interface <code>SalesFormatter</code>. 
  This class is implemented as a singleton so a new object will not be created 
  every time the XML format is used.</p>

<p><em>Static variable:</em></p>
<ul>
  <li><code><em>singletonInstance</em></code>. The single instance of class <code></code><code>XMLSalesFormatter</code>.</li>
</ul>
<p><em>Constructor and methods:</em></p>
<ul>
  <li> <code><em>static public XMLSalesFormatter getSingletonInstance()</em></code>. 
    Static method that obtains the single instance of class <code>XMLSalesFormatter</code>. 
  </li>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -