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

📄 exe6.html

📁 卡耐基课程练习
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<span class="dialogueheader">Take Assessment: Exercise 6</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="657847" 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:57:23 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:57:23 GMT+0800.</td>  <td width="5"><br></td></tr></tbody></table>

<a name="top_14846"></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="#14846">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 File I/O 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>Java API</em>
<ul>
        <li>Knowledge of the class <code>StringTokenizer</code></li>
      </ul>

    </li><li><em>File I/O</em>
<ul>
        <li>Knowledge of file I/O
<ul>
            <li>How to read data from a file</li>
            <li>How to write data to a file</li>
          </ul>
        </li>

      </ul>
  </li></ul>
  <p> <b><i>Goals:</i></b> Reinforce your ability to use file I/O 
  </p><p> <b><i>Outcomes:</i></b> You will master the following skills: 
  </p><ul>
    <li> Produce applications that read data from a file and parse it</li>

    <li> Produce applications that write data to a file</li>
  </ul>
</blockquote>
<h3>Background </h3>

<p>In this assignment, you will create another version of the <em>Gourmet Coffee 
  System</em>. In previous versions, the data for the product catalog was hard-coded 
  in the application. In this version, the data will be loaded from a file. Also, 
  the user will be able to write the sales information to a file in one of 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 loads the 
  product catalog and persists the sales information. </p>
<h3>Description</h3>
<p>The <em>Gourmet Coffee System</em> sells three types of products: coffee, coffee 
  brewers, and accessories for coffee consumption. A file called catalog.dat stores 
  the product data:</p>

<ul>
  <li><code><cite><a href="/content/SSD/SSD3/4.2.0.1/normal/pg-adv-class-impl/pg-io-prgrmng/assm-exer-file-io/pool-pr-io-prgrmng/qn-pr-io-gou-cof/handout/catalog.dat" target="internalWindow"><em>catalog.dat</em></a></cite></code>. 
    File with product data</li>
</ul>
<p>Every line in catalog.dat contains exactly one product. </p>
<p>A line for a coffee product has the following format:</p>
<blockquote> 
  <pre>Coffee_<em>code</em>_<em>description</em>_<em>price</em>_<em>origin</em>_<em>roast</em>_<em>flavor</em>_<em>aroma</em>_<em>acidity</em>_<em>body</em></pre>

</blockquote>
<p>where:</p>
<ul>
  <li>"Coffee" is a prefix that indicates the line type.</li>
  <li><em>code</em> is a string that represents the code of the coffee.</li>
  <li><em>description</em> is a string that represents the description of the 
    coffee.</li>

  <li><em>price</em> is a double that represents the price of the coffee.</li>
  <li><em>origin</em> is a string that represents the origin of the coffee.</li>
  <li><em>roast</em> is a string that represents the roast of the coffee.</li>
  <li><em>flavor</em> is a string that represents the flavor of the coffee.</li>

  <li><em>aroma</em> is a string that represents the aroma of the coffee.</li>
  <li><em>acidity</em> is a string that represents the acidity of the coffee.</li>
  <li><em>body</em> is a string that represents the body of the coffee.</li>
</ul>
<p>The fields are delimited by an underscore ( _ ). You can assume that the fields 
  themselves do not contain any underscores.</p>

<p>A line for a coffee brewer has the following format:</p>
<blockquote> 
  <pre>Brewer_<em>code</em>_<em>description</em>_<em>price</em>_<em>model</em>_<em>waterSupply</em>_<em>numberOfCups</em></pre>
</blockquote>

<p>where:</p>
<ul>
  <li>"Brewer" is a prefix that indicates the line type.</li>
  <li><em>code</em> is a string that represents the code of the brewer.</li>
  <li><em>description</em> is a string that represents the description of the 
    brewer.</li>
  <li><em>price</em> is a double that represents the price of the brewer.</li>

  <li><em>model</em> is a string that represents the model of the coffee brewer.</li>
  <li><em>waterSupply</em> is a string that represents the water supply of the 
    coffee brewer.</li>
  <li><em>numberOfCups</em> is an integer that represents the capacity of the 
    coffee brewer in number of cups.</li>
</ul>
<p>The fields are delimited by an underscore ( <code>_</code> ). You can assume 
  that the fields themselves do not contain any underscores.</p>

<p>A line for a coffee accessory has the following format:</p>
<blockquote> 
  <pre>Product_<em>code</em>_<em>description</em>_<em>price</em></pre>
</blockquote>
<p>where:</p>
<ul>
  <li>"Product" is a prefix that indicates the line type.</li>

  <li><em>code</em> is a string that represents the code of the product.</li>
  <li><em>description</em> is a string that represents the description of the 
    product.</li>
  <li><em>price</em> is a double that represents the price of the product.</li>
</ul>
<p>The fields are delimited by an underscore ( <code>_</code> ). You can assume 
  that the fields themselves do not contain any underscores.</p>

<p>The following class diagram highlights the elements you will use to load the 
  product catalog and persist the sales information:</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-adv-class-impl/pg-io-prgrmng/assm-exer-file-io/pool-pr-io-prgrmng/qn-pr-io-gou-cof/handout/images/io-gou-cof.jpg" alt="Figure 1 Portion of Gourmet Coffee System class diagram" height="368" width="541"></td>
    </tr>
    <tr> 
      <td><strong>Figure 1 </strong><em>Portion of Gourmet Coffee System class diagram</em></td>
    </tr>
  </tbody></table>

</blockquote>
<p>In this assignment, you will implement <code>FileCatalogloader</code> and complete 
  the implementation of <code>GourmetCoffee.</code></p>
<h4>Interface <code>CatalogLoader</code></h4>
<p>The interface <code>CatalogLoader</code> declares a method for producing a 
  product catalog. A complete implementation of this interface is provided in 
  the student archive.</p>
<p><em>Method:</em></p>

<ul>
  <li> <pre><em>Catalog loadCatalog(String fileName)
    throws FileNotFoundException,
           IOException,
           DataFormatException</em></pre>
    Loads the information in the specified file into a product catalog and returns 
    the catalog.</li>
</ul>

<h4>Class <code>DataFormatException</code></h4>
<p>This exception<code></code> is thrown when a line in the file being parsed 
  has errors:</p>

<ul>
  <li>The line does not have the expected number of tokens.</li>
  <li>The tokens that should contain numbers do not.</li>
</ul>
<p>A complete implementation of this class is provided in the student archive.</p>
<h4>Class <code>FileCatalogLoader</code></h4>
<p>The class <code>FileCatalogLoader</code> implements interface <code>CatalogLoader</code>. 
  It is used to obtain a product catalog from a file. You should implement this 
  class from scratch:</p>

<p><em>Methods:</em></p>
<ul>
  <li><pre><em>private Product readProduct(String line)
    throws DataFormatException</em></pre>
    This method reads a line of coffee-accessory data. It uses the class <code>StringTokenizer</code> 
    to extract the accessory data in the specified line. If the line is error 
    free, this method returns a <code>Product</code> object that encapsulates 
    the accessory data. If the line has errors, that is, if it does not have the 
    expected number of tokens or the token that should contain a double does not; 
    this method throws a <code></code><code>DataFormatException</code> that contains 
    the line of malformed data.</li>

</ul>
<ul>
  <li>
    <pre><em>private Coffee readCoffee(String line)
    throws DataFormatException</em></pre>
    This method reads a line of coffee data. It uses the class <code>StringTokenizer</code> 
    to extract the coffee data in the specified line. If the line is error free, 
    this method returns a <code>Coffee</code> object that encapsulates the coffee 
    data. If the line has errors, that is, if it does not have the expected number 
    of tokens or the token that should contain a double does not; this method 
    throws a <code></code><code>DataFormatException</code> that contains the line 
    of malformed data. </li>

</ul>
<ul>
  <li><pre><em>private CoffeeBrewer readCoffeeBrewer(String line) 
    throws DataFormatException</em></pre>
    This method reads a line of coffee-brewer data. It uses the class <code>StringTokenizer</code> 
    to extract the brewer data in the specified line. If the line is error free, 
    this method returns a <code>CoffeeBrewer</code> object that encapsulates the 
    brewer data. If the line has errors, that is, if it does not have the expected 
    number of tokens or the tokens that should contain a number do not; this method 
    throws a <code></code><code>DataFormatException</code> that contains the line 
    of malformed data. </li>

</ul>
<ul>
  <li>
    <pre><em>public Catalog loadCatalog(String filename)
    throws FileNotFoundException, 
           IOException,
           DataFormatException</em></pre>

⌨️ 快捷键说明

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