📄 exe6.html
字号:
<p>This method loads the information
in the specified file into a product catalog and returns the catalog. It begins
by opening the file for reading. It then proceeds to read and process each
line in the file. The method <a href="http://java.sun.com/j2se/1.5/docs/api/java/lang/String.html#startsWith%28java.lang.String%29" target="externalWindow"><code>String.startsWith</code></a>
is used to determine the line type:
</p></li></ul>
<ul>
<ul>
<li>If the line type is "Product", the method <code>readProduct</code>
is invoked.</li>
<li>If the line type is "Coffee", the method <code>readCoffee</code>
is invoked.</li>
<li>If the line type is "Brewer", the method <code>readCoffeeBrewer</code>
is invoked.</li>
</ul>
</ul>
<blockquote>
<p>After the line is processed, <code>loadCatalog</code> adds the product (accessory,
coffee, or brewer) to the product catalog. When all the lines in the file
have been processed, <code>load</code> returns the product catalog to the
calling method. </p>
<p>This method can throw the following exceptions: </p>
<blockquote>
<ul>
<li><code>FileNotFoundException</code> — if the specified file does
not exist.</li>
<li><code>IOException</code> — if there is an error reading the information
in the specified file.</li>
<li><code>DataFormatException</code> — if a line in the file has errors
(the exception should contain the line of malformed data).</li>
</ul>
</blockquote>
</blockquote>
<h4>Class <code>GourmetCoffee</code></h4>
<p>A partial implementation of class <code>GourmetCoffee</code> is provided in
the student archive. You should implement <code>writeFile</code>, a method that
writes sales information to a file:</p>
<ul>
<li>
<pre><em>private void writeFile(String fileName, String content)
throws IOException</em> </pre>
<p>This method creates a new file with the specified
name, writes the specified string to the file, and then closes the file.</p></li>
</ul>
<h4>Class <code>TestFileCatalogLoader</code></h4>
<p>This class is a test driver for <code>FileCatalogLoader</code>. A complete
implementation is included in the student archive <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/student-files.zip"><code>student-files.zip</code></a></cite>.
You should use this class to test your implementation of <code>FileCatalogLoader</code>.
</p>
<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-adv-class-impl/pg-io-prgrmng/assm-exer-file-io/pool-pr-io-prgrmng/qn-pr-io-gou-cof/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>
<li><cite><code>SalesFormatter.class</code></cite></li>
<li><cite><code>PlainTextSalesFormatter.class</code></cite></li>
<li><cite><code>HTMLSalesFormatter.class</code></cite></li>
<li><cite><code>XMLSalesFormatter.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> </li>
<li><cite><code>Catalog.html</code></cite> </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>
<li><cite><code>SalesFormatter.html</code></cite></li>
<li><cite><code>PlainTextSalesFormatter.html</code></cite></li>
<li><cite><code>HTMLSalesFormatter.html</code></cite></li>
<li><cite><code>XMLSalesFormatter.html</code></cite></li>
</ul>
</li>
<li>Java files
<ul>
<li><cite><code>CatalogLoader.java</code></cite>. A complete implementation</li>
<li><cite><code>DataFormatException.java</code></cite>. A complete implementation</li>
<li><code><cite>TestFileCatalogLoader.java</cite></code>. A complete
implementation</li>
<li><cite><code>GourmetCoffee.java</code></cite>. Use this template
to complete your implementation.</li>
</ul>
</li>
<li>Data files for the test driver
<ul>
<li><cite><code>catalog.dat</code></cite>. A file with product information</li>
<li><cite><code>empty.dat</code></cite>. An empty file</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3>Tasks </h3>
<p>Implement the class <code>FileCatalogLoader</code> and the method <code>GourmetCoffee.writeFile</code><code></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:\></tt><kbd>unzip student-files.zip</kbd> </p>
</li>
<li><strong>Then</strong>, implement class <code>FileCatalogLoader</code> from
scratch. Use the <code>TestFileCatalogLoader</code> driver to test your implementation.
</li>
</ol>
<ol start="3">
<li><strong>Next</strong>, implement the method <code>GourmetCoffee.writeFile</code>.</li>
</ol>
<ol start="4">
<li><strong>Finally</strong>, compile the class <code>GourmetCoffee</code>,
and execute the class <code>GourmetCoffee</code> by issuing the following
command at the command prompt:
<p><tt>C:\></tt><kbd>java GourmetCoffee catalog.dat</kbd> </p>
<p>Sales information has been hard-coded in the <code>GourmetCoffee</code>
template provided by iCarnegie.</p>
</li>
<ul>
<li>If the user displays the catalog, the output should be: </li>
<blockquote>
<pre>C001 Colombia, Whole, 1 lb<br>C002 Colombia, Ground, 1 lb<br>C003 Italian Roast, Whole, 1 lb<br>C004 Italian Roast, Ground, 1 lb<br>C005 French Roast, Whole, 1 lb<br>C006 French Roast, Ground, 1 lb<br>C007 Guatemala, Whole, 1 lb<br>C008 Guatemala, Ground, 1 lb<br>C009 Sumatra, Whole, 1 lb<br>C010 Sumatra, Ground, 1 lb<br>C011 Decaf Blend, Whole, 1 lb<br>C012 Decaf Blend, Ground, 1 lb<br>B001 Home Coffee Brewer<br>B002 Coffee Brewer, 2 Warmers<br>B003 Coffee Brewer, 3 Warmers<br>B004 Commercial Coffee, 20 Cups<br>B005 Commercial Coffee, 40 Cups<br>A001 Almond Flavored Syrup<br>A002 Irish Creme Flavored Syrup<br>A003 Mint Flavored syrup<br>A004 Caramel Flavored Syrup<br>A005 Gourmet Coffee Cookies<br>A006 Gourmet Coffee Travel Thermo<br>A007 Gourmet Coffee Ceramic Mug<br>A008 Gourmet Coffee 12 Cup Filters<br>A009 Gourmet Coffee 36 Cup Filters</pre>
</blockquote>
<li>If the user saves the sales information in plain text, a file with the
following content should be created: </li>
<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>If the user saves the sales information in HTML, a file with the following
content should be created:
<blockquote>
<pre><html><br> <body><br> <center><h2>Orders</h2></center><br> <hr><br> <h4>Total = 89.94999999999999</h4><br> <p><br> <b>code:</b> C001<br><br> <b>quantity:</b> 5<br><br> <b>price:</b> 17.99<br> </p><br> <hr><br> <h4>Total = 55.5</h4><br> <p><br> <b>code:</b> C002<br><br> <b>quantity:</b> 2<br><br> <b>price:</b> 18.75<br> </p><br> <p><br> <b>code:</b> A001<br><br> <b>quantity:</b> 2<br><br> <b>price:</b> 9.0<br> </p><br> <hr><br> <h4>Total = 200.0</h4><br> <p><br> <b>code:</b> B002<br><br> <b>quantity:</b> 1<br><br> <b>price:</b> 200.0<br> </p><br> </body><br></html></pre>
</blockquote>
</li>
<li>If the user saves the sales information in XML, a file with the following
content should be created:
<blockquote>
<pre><Sales><br> <Order total="89.94999999999999"><br> <OrderItem quantity="5" price="17.99">C001</OrderItem><br> </Order><br> <Order total="55.5"><br> <OrderItem quantity="2" price="18.75">C002</OrderItem><br> <OrderItem quantity="2" price="9.0">A001</OrderItem><br> </Order><br> <Order total="200.0"><br> <OrderItem quantity="1" price="200.0">B002</OrderItem><br> </Order><br></Sales></pre>
</blockquote>
</li>
</ul>
</ol>
<h3>Submission</h3>
<p>Upon completion, submit <strong>only</strong> the following:</p>
<ol>
<li><code>FileCatalogLoader.java</code></li>
<li><code>GourmetCoffee.java</code></li>
</ol>
</td>
<td width="5"><br></td></tr></tbody></table>
<a name="14846"></a><table><tbody><tr>
<td width="5"><br></td> <td class="td0_x" align="left" valign="top"> <a href="#top_14846">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_14846">File to submit:</label><br> <input class="x" name="file_to_add_14846" 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=14846", 14846, false)' type="submit"></td><td width="5"><br></td></tr></tbody></table>
<hr><input name="pr_state_14846" id="pr_state_14846" value="a:2:{i:0;s:10:"incomplete";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:57:23 UTC" id="end_date" name="end_date" type="hidden"> <input value="421063" id="course_section_id" name="course_section_id" type="hidden"> <input value="14843" id="assm_id" name="assm_id" type="hidden"> <input value="657847" id="template_id" name="template_id" type="hidden"> <input value="657848" 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 + -