?? exe4.html
字號:
<span class="dialogueheader">Take Assessment: Exercise 4</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="657801" 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:54:58 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:54:58 GMT+0800.</td> <td width="5"><br></td></tr></tbody></table>
<a name="top_14421"></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="#14421">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 042903 ici -->
<h2 align="center">Implementing the Collections 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>Collections</em>
<ul>
<li>Use of class <code>ArrayList</code></li>
<li>Use of iterators</li>
</ul>
</li></ul>
<p> <b><i>Goals:</i></b> Reinforce your ability to implement classes that use
collections
</p><p> <b><i>Outcomes:</i></b> You
will demonstrate mastery of the following:
</p><ul>
<li>Implementing a Java class that uses collections</li>
</ul>
</blockquote>
<h3>Background </h3>
<p>In this assignment, you will implement the classes in
the <em>Gourmet Coffee
System</em> that use collections.</p>
<h3>Description</h3>
<p>The following class diagram of the <em>Gourmet Coffee System</em> highlights
the classes that use collections:</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-collctns/assm-exer-impl-collctns/pool-pr-impl-collctns/qn-pr-collctns-cof-gou-sys/handout/images/coll-cof-gou-sys.jpg" alt="Figure 1 Gourmet Coffee System class diagram" height="558" width="621"></td>
</tr>
<tr>
<td><b>Figure 1 </b><i>Gourmet Coffee System class diagram</i></td>
</tr>
</tbody></table>
</blockquote>
<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>OrderItem</code></li>
<li><code>GourmetCoffee</code></li>
</ul>
<p>In this assignment, you will implement the following classes:</p>
<ul>
<li><code>Catalog</code></li>
<li><code>Order</code></li>
<li><code>Sales</code></li>
<li><code>GourmetCoffee</code></li>
</ul>
<p>The class specifications are as follows:</p>
<h4>Class <code>Catalog</code></h4>
<p>The class <code>Catalog</code> models a product catalog. This class implements the interface <code>Iterable<Product></code> to being able to iterate through the products using the <code>for-each</code> loop.</p>
<p><em>Instance variables:</em></p>
<ul>
<li><code><em>products</em></code> — An <code>ArrayList</code> collection that contains references to instances
of class <code>Product</code>.</li>
</ul>
<p><em>Constructor and public methods:</em></p>
<ul>
<li> <code><em>public Catalog()</em></code> — Creates the collection <code>products</code>,
which is initially empty.</li>
</ul>
<ul>
<li> <code><em>public void addProduct(Product product)</em></code> — Adds the
specified product to the collection <code>products</code>.</li>
</ul>
<ul>
<li> <code><em>public Iterator<Product> iterator()</em></code> — Returns an
iterator over the instances in the collection <code>products</code>.</li>
</ul>
<ul>
<li> <code><em>public Product getProduct(String code)</em></code> — Returns a
reference to the <code>Product</code> instance with the specified code. Returns
<code>null</code> if there are no products in the catalog with the specified
code. </li>
</ul>
<ul>
<li> <code><em>public int getNumberOfProducts()</em></code> — Returns the number
of instances in the collection <code>products</code>.</li>
</ul>
<h4>Class <code>Order</code></h4>
<p>The class <code>Order</code> maintains a list of order items. This class implements the interface <code>Iterable<OrderItem></code> to being able to iterate through the items using the <code>for-each</code> loop.</p>
<p><em>Instance variables:</em></p>
<ul>
<li><code><em>items</em></code> — An <code>ArrayList</code> collection that contains references to instances
of class <code>OrderItem</code>.</li>
</ul>
<p><em>Constructor and public methods:</em></p>
<ul>
<li> <code><em>public Order()</em></code> — Creates the collection <code>items</code>,
which is initially empty.</li>
</ul>
<ul>
<li> <code><em>public void addItem(OrderItem orderItem)</em></code> — Adds the
specified order item to the collection <code>items</code>.</li>
</ul>
<ul>
<li> <code><em>public void removeItem(OrderItem orderItem)</em></code> — Removes
the specified order item from the collection <code>items</code>.</li>
</ul>
<ul>
<li> <code><em>public Iterator<OrderItem> iterator()</em></code> — Returns an iterator
over the instances in the collection <code>items</code>.</li>
</ul>
<ul>
<li> <code><em>public OrderItem getItem(Product product)</em></code> — Returns
a reference to the <code>OrderItem</code> instance with the specified product.
Returns <code>null</code> if there are no items in the order with the specified
product.</li>
</ul>
<ul>
<li> <code><em>public int getNumberOfItems()</em></code> — Returns the number
of instances in the collection <code>items</code>.</li>
</ul>
<ul>
<li> <code><em>public double getTotalCost()</em></code> — Returns the total cost
of the order. </li>
</ul>
<h4>Class <code>Sales</code></h4>
<p>The class <code>Sales</code> maintains a list of the orders that have been
completed. This class implements the interface <code>Iterable<Order></code> to being able to iterate through the orders using the <code>for-each</code> loop.</p>
<p><em>Instance variables:</em></p>
<ul>
<li><code><em>orders</em></code> — An <code>ArrayList</code> collection that contains references to instances
of class <code>Order</code>.</li>
</ul>
<p><em>Constructor and public methods:</em></p>
<ul>
<li> <code><em>public Sales()</em></code> — Creates the collection <code>orders</code>,
which is initially empty.</li>
</ul>
<ul>
<li> <code><em>public void addOrder(Order order)</em></code> — Adds the specified
order to the collection <code>orders</code>.</li>
</ul>
<ul>
<li> <code><em>public Iterator<Order> iterator()</em></code> — Returns an iterator
over the instances in the collection <code>orders</code>.</li>
</ul>
<ul>
<li> <code><em>public int getNumberOfOrders()</em></code> — Returns the number
of instances in the collection <code>orders</code>.</li>
</ul>
<h4>Class <code>GourmetCoffee</code></h4>
<p>The class <code>GourmetCoffee</code> creates a console interface to process store orders. Currently, it includes
the complete implementation of some of the methods. The methods <code>displayNumberOfOrders</code> and <code>displayTotalQuantityOfProducts</code> are incomplete and should be implemented. The following is a screen shot of the interface:</p>
<blockquote>
<table border="0" cellpadding="2" cellspacing="2" width="54%">
<tbody><tr>
<td><img src="/content/SSD/SSD3/4.2.0.1/normal/pg-class-imp/pg-collctns/assm-exer-impl-collctns/pool-pr-impl-collctns/qn-pr-collctns-cof-gou-sys/handout/images/exe-gourmet-coffee.jpg" alt="Figure 2 Execution of GourmetCoffee" height="149" width="430"></td>
</tr>
<tr>
<td><b>Figure 2</b> <i>Execution of GourmetCoffee</i></td>
</tr>
</tbody></table>
</blockquote>
<p><em>Instance variables:</em></p>
<ul>
<li><code><em>catalog</em></code> — A <code>Catalog</code> object with the products that can be sold.</li>
<li><code><em>currentOrder</em></code> — An <code>Order</code> object with the information about the current order.</li>
<li><code><em>sales</em></code> — A <code>Sales</code> object with information about all the orders sold by the store.</li>
</ul>
<p><em>Constructor and public methods:</em></p>
<ul>
<li> <code><em>public GourmetCoffeeSolution()</em></code> — Initializes the attributes <code>catalog</code>, <code>currentOrder</code> and <code>sales</code>. This constructor is complete and should not be modified.</li>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -