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

📄 exe5.html

📁 卡耐基课程练习
💻 HTML
📖 第 1 页 / 共 2 页
字号:
</ul>
<ul>
  <li> <code><em>private XMLSalesFormatter()</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>XMLSalesFormatter</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 XML format.</li>
</ul>

<blockquote> 
  <ul>
    <li>The string should begin with the following XML: </li>
    <blockquote> 
      <pre>&lt;Sales&gt;</pre>
    </blockquote>
    <li>Each order in the sales information should have the following format: 
      <pre>  &lt;Order total="<em>totalCost</em>"&gt;<br>    &lt;OrderItem quantity="<em>quantity1</em>" price="<em>price1</em>"&gt;<em>code1</em>&lt;/OrderItem&gt;

    ...<br>    &lt;OrderItem quantity="<em>quantityN</em>" price="<em>priceN</em>"&gt;<em>codeN</em>&lt;/OrderItem&gt;<br>  &lt;/Order&gt;</pre>
      <p> where:</p>

    </li>
  </ul>
  <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 XML: 
      <blockquote> 
        <pre>&lt;/Sales&gt;</pre>

      </blockquote>
    </li>
  </ul>
</blockquote>
<h4>Class <code>GourmetCoffee</code></h4>
<p>Class <code>GourmetCoffee</code> lets the user display the sales information 
  in one of three formats: plain text, HTML, or XML. A partial implementation 
  of this class is provided in the student archive. </p>
<p><em>Instance variables:</em></p>

<ul>
  <li><code><em>private Sales sales</em></code>. A list of the orders that have 
    been paid for.</li>
</ul>
<ul>
  <li><code><em>private SalesFormatter salesFormatter</em></code>. A reference 
    variable that refers to the current formatter: a <code>PlainTextSalesFormatter</code>, 
    <code>HTMLSalesFormatter</code>, or <code>XMLSalesFormatter</code> object.</li>

</ul>
<p><em>Constructor and methods:</em></p>
<p>The following methods and constructor are complete and require no modification:</p>
<ul>
  <li> <code><em>public static void main(String[] args) throws IOException</em></code>. 
    Starts the application.</li>
</ul>
<ul>
  <li> <code><em>private GourmetCoffee()</em></code>. Initialize instance variables 
    <code>sales</code> and <code>salesFormatter</code>.</li>

</ul>
<ul>
  <li> <code><em>private Catalog loadCatalog()</em></code>.Populates the product 
    catalog.</li>
</ul>
<ul>
  <li> <code><em>private void loadSales(Catalog catalog)</em></code>. Populates 
    the <code>sales</code> object.</li>

</ul>
<ul>
  <li><code><em>private int getChoice() throws IOException</em></code>. Displays 
    a menu of options and verifies the user's choice.</li>
</ul>
<p>The following methods should be completed:</p>
<ul>
  <li><code><em>private void setSalesFormatter(SalesFormatter newFormatter)</em></code>. 
    Changes the current formatter by updating the instance variable <code>salesFormatter</code> 
    with the object specified in the parameter <code>newFormatter</code>.</li>

</ul>
<ul>
  <li><code><em>private void displaySales()</em></code>. Displays the sales information 
    in the standard output using the method <code>salesFormatter.formatSales</code> 
    to obtain the sales information in the current format.</li>
</ul>
<ul>
  <li><code><em>private void run() throws IOException</em></code>. Presents the 
    user with a menu of options and executes the selected task </li>
</ul>
<ul>

  <ul>
    <li>If the user chooses option 1, <code>run</code> calls method <code>setSalesFormatter</code> 
      with the singleton instance of class <code>PlainTextSalesFormatter</code>, 
      and calls method <code>displaySales</code> to display the sales information 
      in the standard output.</li>
  </ul>

</ul>
<ul>
  <ul>
    <li>If the user chooses option 2, <code>run</code> calls method <code>setSalesFormatter</code> 
      with the singleton instance of class <code>HTMLSalesFormatter</code>, and 
      calls method <code>displaySales</code> to display the sales information 
      in the standard output.</li>

  </ul>
</ul>
<ul>
  <ul>
    <li>If the user chooses option 3, <code>run</code> calls method <code>setSalesFormatter</code> 
      with the singleton instance of class <code>XMLTextSalesFormatter</code>, 
      and calls method <code>displaySales</code> to display the sales information 
      in the standard output.</li>

  </ul>
</ul>
<h3>Files</h3>
The following files are needed to complete this assignment: 
<ul>
  <li><cite><a href="/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/student-files.zip"><code>student-files.zip</code></a></cite> 
    — Download this file. This archive contains the following: 
    <ul>
      <li>Class files 
        <ul>
          <li><cite><code>Coffee.class</code></cite></li>

          <li><cite><code>CoffeeBrewer.class</code></cite></li>
          <li><cite><code>Product.class</code></cite> </li>
          <li><cite><code>Catalog.class</code></cite> </li>
          <li><cite><code>OrderItem.class</code></cite> </li>
          <li><cite><code>Order.class</code></cite> </li>

          <li><cite><code>Sales.class</code></cite></li>
        </ul>
      </li>
      <li>Documentation 
        <ul>
          <li><cite><code>Coffee.html</code></cite></li>
          <li><cite><code>CoffeeBrewer.html</code></cite></li>
          <li><cite><code>Product.html</code></cite><code><cite> </cite></code></li>

          <li><cite><code>Catalog.html</code></cite><code><cite></cite></code> 
          </li>
          <li> <cite><code>OrderItem.html</code></cite> </li>
          <li><cite><code>Order.html</code></cite> </li>
          <li><cite><code>Sales.html</code></cite> </li>

        </ul>
      </li>
      <li><cite><code>GourmetCoffee.java</code></cite>. A partial implementation 
        of the class <code>GourmetCoffee</code>.</li>
    </ul>
  </li>
</ul>
<h3>Tasks </h3>

<p>Implement the interface <code>SalesFormatter</code> and the classes <code>PlainTextSalesFormatter</code>, 
  <code>HTMLSalesFormatter</code>, <code>XMLSalesFormatter</code>. Finish the 
  implementation of class <code>GourmetCoffee</code>. Document using Javadoc and 
  follow Sun's code conventions. The following steps will guide you through this 
  assignment. Work incrementally and test each increment. Save often.</p>
<ol start="1">
  <li><strong>Extract </strong> the files by
    issuing the following command at  the command prompt:
    <p><tt>C:\&gt;</tt><kbd>unzip student-files.zip</kbd> </p>

  </li>
  <li><strong>Then</strong>, implement interface <code>SalesFormatter</code> from 
    scratch.</li>
</ol>
<ol start="3">
  <li><strong>Next</strong>, implement class <code>PlainTextSalesFormatter</code> 
    from scratch.</li>

</ol>
<ol start="4">
  <li><strong>Then</strong>, implement class <code>HTMLSalesFormatter</code> from 
    scratch.</li>
</ol>
<ol start="5">
  <li><strong>Next</strong>, implement class <code>XMLSalesFormatter</code> from 
    scratch.</li>

</ol>
<ol start="6">
  <li><strong>Then</strong>, complete the method <code>GourmetCoffee.setSalesFormatter</code>.</li>
</ol>
<ol start="7">
  <li><strong>Next</strong>, complete the method <code>GourmetCoffee.</code><code>displaySales</code>.</li>

</ol>
<ol start="8">
  <li><strong>Then</strong>, complete the method <code>GourmetCoffee.run</code>.</li>
</ol>
<ol start="9">
  <li><strong>Finally</strong>, compile and execute the class <code>GourmetCoffee</code>. 
    Sales information has been hard-coded in the <code>GourmetCoffee</code> template 
    provided by iCarnegie. 
    <p></p>

    <ul>
      <li>If the user chooses to display the sales information in plain text, 
        the output should be: 
        <blockquote> 
          <pre>------------------------
Order 1

5 C001 17.99

Total = 89.94999999999999
------------------------
Order 2

2 C002 18.75
2 A001 9.0

Total = 55.5
------------------------
Order 3

1 B002 200.0

Total = 200.0</pre>
        </blockquote>
      </li>
      <li>If the user chooses to display the sales information in HTML, the output 
        should be: 
        <blockquote> 
          <pre>&lt;html&gt;<br>  &lt;body&gt;<br>    &lt;center&gt;&lt;h2&gt;Orders&lt;/h2&gt;&lt;/center&gt;<br>    &lt;hr&gt;<br>    &lt;h4&gt;Total = 89.94999999999999&lt;/h4&gt;<br>      &lt;p&gt;<br>        &lt;b&gt;code:&lt;/b&gt; C001&lt;br&gt;<br>        &lt;b&gt;quantity:&lt;/b&gt; 5&lt;br&gt;<br>        &lt;b&gt;price:&lt;/b&gt; 17.99<br>      &lt;/p&gt;<br>    &lt;hr&gt;<br>    &lt;h4&gt;Total = 55.5&lt;/h4&gt;<br>      &lt;p&gt;<br>        &lt;b&gt;code:&lt;/b&gt; C002&lt;br&gt;<br>        &lt;b&gt;quantity:&lt;/b&gt; 2&lt;br&gt;<br>        &lt;b&gt;price:&lt;/b&gt; 18.75<br>      &lt;/p&gt;<br>      &lt;p&gt;<br>        &lt;b&gt;code:&lt;/b&gt; A001&lt;br&gt;<br>        &lt;b&gt;quantity:&lt;/b&gt; 2&lt;br&gt;<br>        &lt;b&gt;price:&lt;/b&gt; 9.0<br>      &lt;/p&gt;<br>    &lt;hr&gt;<br>    &lt;h4&gt;Total = 200.0&lt;/h4&gt;<br>      &lt;p&gt;<br>        &lt;b&gt;code:&lt;/b&gt; B002&lt;br&gt;<br>        &lt;b&gt;quantity:&lt;/b&gt; 1&lt;br&gt;<br>        &lt;b&gt;price:&lt;/b&gt; 200.0<br>      &lt;/p&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;

        </pre>
        </blockquote>
      </li>
      <li>If the user chooses to display the sales information in XML, the output 
        should be: 
        <blockquote> 
          <pre>&lt;Sales&gt;<br>  &lt;Order total="89.94999999999999"&gt;<br>    &lt;OrderItem quantity="5" price="17.99"&gt;C001&lt;/OrderItem&gt;<br>  &lt;/Order&gt;<br>  &lt;Order total="55.5"&gt;<br>    &lt;OrderItem quantity="2" price="18.75"&gt;C002&lt;/OrderItem&gt;<br>    &lt;OrderItem quantity="2" price="9.0"&gt;A001&lt;/OrderItem&gt;<br>  &lt;/Order&gt;<br>  &lt;Order total="200.0"&gt;<br>    &lt;OrderItem quantity="1" price="200.0"&gt;B002&lt;/OrderItem&gt;<br>  &lt;/Order&gt;<br>&lt;/Sales&gt;

        </pre>
        </blockquote>
      </li>
    </ul>
  </li>
</ol>

<h3>Submission</h3>
<p>Upon completion, submit <strong>only</strong> the following:</p>

<ol>
  <li><code>SalesFormatter.java</code></li>
  <li><code>PlainTextSalesFormatter.java</code></li>
  <li><code>HTMLSalesFormatter.java</code></li>
  <li><code>XMLSalesFormatter.java</code></li>
  <li><code>GourmetCoffee.java</code></li>
</ol>

 </td>
<td width="5"><br></td></tr></tbody></table>
<a name="14555"></a><table><tbody><tr>
<td width="5"><br></td>  <td class="td0_x" align="left" valign="top"> <a href="#top_14555">Go to top of question.</a> </td>
<td width="5"><br></td></tr></tbody></table>
<hr><table><tbody><tr>
<td width="5"><br></td>  <td class="td0_x" align="left" valign="top"><label class="lbl0-x" for="file_to_add_14555">File to submit:</label><br> <input class="x" name="file_to_add_14555" value="" size="20" maxlength="500" type="file"> </td>
<td width="5"><br></td><td valign="bottom">  <input class="x" value="Upload File" name="add_file" id="add_file" style="width: 12em;" onclick='return SetUploadTime("https://seqcc.icarnegie.com:443/takeassmcmd.php?question_id=14555", 14555, false)' type="submit"></td><td width="5"><br></td></tr></tbody></table>

<hr><input name="pr_state_14555" id="pr_state_14555" value="a:2:{i:0;s:10:&quot;incomplete&quot;;i:1;a:0:{}}" type="hidden"><table><tbody><tr>
  </tr></tbody></table>
<input name="max_mins_per_try" id="max_mins_per_try" value="120" type="hidden">  <input value="2008-11-29 10:56:22 UTC" id="end_date" name="end_date" type="hidden">  <input value="421063" id="course_section_id" name="course_section_id" type="hidden">  <input value="14552" id="assm_id" name="assm_id" type="hidden">  <input value="657817" id="template_id" name="template_id" type="hidden">  <input value="657818" id="record_id" name="record_id" type="hidden">  <input value="" id="client_time" name="client_time" type="hidden"><table><tbody><tr>
<td width="5"><br></td>  <td class="td0_x" align="left" valign="top"> <a href="#top_of_page">Go to top of assessment.</a> </td>
  </tr></tbody></table>

<table><tbody><tr>
<td width="5"><br></td>  <td class="td0_copyright" align="left" valign="top"> ? Copyright 2006 iCarnegie, Inc.  All rights reserved. </td>
</tr></tbody></table>
</form>


⌨️ 快捷键说明

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