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

📄 takeassmcmd[1].html

📁 ssd exercise1.自己做的
💻 HTML
📖 第 1 页 / 共 2 页
字号:
  <li>Choice 0 terminates the program.</li>
  <li>Choice 1 adds a product to the shopping cart<cite></cite>.</li>
  <li>Choice 2 displays the information of all the products stored in the shopping 
    cart.</li>
  <li>Choice 3 displays the total cost of all the products in the shopping cart<cite></cite>.</li>
</ul>
<p>To add a product, the user enters a line with the following format:</p>

<blockquote> <em>name_quntity_price</em> </blockquote>

<p>Where:</p>
<ul>
  <li><em>name</em> is the name of the product.</li>
  <li><em>quantity</em> is the quantity of the product.</li>
  <li><em>price</em> is the price of the product.</li>
</ul>
<p>The fields are delimited by an underscore ( <code>_</code> ). If the user's 
  input is invalid, the application displays an error message.</p>

<p>The following is a screen shot of the application after some products have 
  been added.</p>
<blockquote> 
  <table cellpadding="2" width="24%" cellspacing="2" border="0">
    <tr> 
      <td><img width="405" height="305" src="picture/shopping-cart-execution.jpg" alt="Figure 1 Execution of ShoppingCartApplication"></td>
    </tr>
    <tr> 
      <td><strong>Figure 1</strong><em> Execution of ShoppingCartApplication</em></td>
    </tr>
  </table></blockquote>  
  
<p>The application uses classes <code>Product</code> and <code>ShoppingCart</code>. 
  <code>ShoppingCart</code> maintains a collection of products. Complete implementations 
  of both are provided in the student archive <cite><a href="/content/SSD/SSD3/4.2.0.1/normal/pg-class-dsgn/pg-java-apps/assm-exer-read-obj-data/pool-pr-apps-io-tokenzr-excptns/qn-pr-shopping-cart/handout/student-files.zip"><code>student-files.zip</code></a></cite>. 
  Review their documentation and become familiar with it. </p>
<ul>
  <li><a href="/content/SSD/SSD3/4.2.0.1/normal/pg-class-dsgn/pg-java-apps/assm-exer-read-obj-data/pool-pr-apps-io-tokenzr-excptns/qn-pr-shopping-cart/handout/Product.html" target="externalWindow"><code><em>Product</em></code></a>. 
    Documentation for class <code>Product</code></li>
  <li><a href="/content/SSD/SSD3/4.2.0.1/normal/pg-class-dsgn/pg-java-apps/assm-exer-read-obj-data/pool-pr-apps-io-tokenzr-excptns/qn-pr-shopping-cart/handout/ShoppingCart.html" target="externalWindow"><code><em>ShoppingCart</em></code></a>. 
    Documentation for class <code>ShoppingCart</code></li>
</ul>

<p>A partial implement of <code>ShoppingCartApplication</code> is provided in 
  the student archive <cite><a href="/content/SSD/SSD3/4.2.0.1/normal/pg-class-dsgn/pg-java-apps/assm-exer-read-obj-data/pool-pr-apps-io-tokenzr-excptns/qn-pr-shopping-cart/handout/student-files.zip"><code>student-files.zip</code></a></cite>. 
  It contains some variables declarations and three methods that need no modification. 
  You should complete method <code>readProduct</code>, the method that reads product 
  information from the keyboard and returns a <code>Product</code> object.</p>
<h3>Files</h3>
The following files are needed to complete this assignment: 
<ul>
  <li><a href="/content/SSD/SSD3/4.2.0.1/normal/pg-class-dsgn/pg-java-apps/assm-exer-read-obj-data/pool-pr-apps-io-tokenzr-excptns/qn-pr-shopping-cart/handout/exe-shopping-cart.jar"><code><cite>exe-shopping-cart.jar</cite></code></a>. 
    Download this file. It is the sample executable.</li>
  <li> <cite><a href="/content/SSD/SSD3/4.2.0.1/normal/pg-class-dsgn/pg-java-apps/assm-exer-read-obj-data/pool-pr-apps-io-tokenzr-excptns/qn-pr-shopping-cart/handout/student-files.zip"><code>student-files.zip</code></a></cite>. 
    Download this file. This archive contains the following:</li>
  <ul>
    <li><cite><code>Product.class</code></cite>. A complete implementation</li>
    <li> <cite><code>ShoppingCart.class</code></cite>. A complete implementation</li>
    <li><cite><code>Product.html</code></cite>. Documentation</li>
    <li> <cite><code>ShoppingCart.html</code></cite>. Documentation</li>
    <li><cite><code>ShoppingCartApplication.java</code></cite> &#151; Use this 
      template to complete your implementation.</li>
  </ul>
</ul>


<h3>Tasks</h3>


  
<p>To complete this assignment, you will finish the implementation of class <code>ShoppingCartApplication</code>. 
  The following steps will guide you through this assignment. Document using Javadoc 
  and follow Sun's code conventions. Work incrementally and test each increment. 
  Save often. </p>
<ol>
  <li><strong>Extract</strong> the student archive by issuing the following command 
    at the command prompt: 
    <blockquote><tt>C:\&gt;</tt><kbd>unzip student-files.zip</kbd></blockquote>
  </li>
</ol>
<ol start="2">
  <li><strong>Run</strong> the sample executable by issuing the following command 
    at the command prompt: 
    <blockquote><tt>C:\&gt;</tt><kbd>java -jar exe-shopping-cart.jar</kbd> </blockquote>
    <p>Observe how the program responds to the following types of input:</p>
    <ul>
      <li> Input with a quantity that is not a valid integer: <kbd>MP3 Player_1.0_150.0</kbd></li>
      <li> Input with a price that is not a valid double: <kbd></kbd><kbd>MP3 
        Player_1_A</kbd>.</li>
      <li>Input that contains negative numbers: <kbd>MP3 Player_-1_150.0</kbd>, 
        or <kbd>MP3 Player_1_-150.0</kbd>.</li>
      <li>Input that contains more than three values: <kbd>MP3 Player_1_150.0_1</kbd>.</li>
      <li>Input that contains fewer than three values: <kbd>MP3 Player_1</kbd>.</li>
      <li>Valid input: <kbd>MP3 Player_1_150.0</kbd>, and <kbd>CD Walkman_2_48.75</kbd>.</li>
    </ul>
  </li>
</ol>
<ol start="2">
  <li> <strong>Then</strong>, complete method <code>readProduct</code>: </li>
</ol>
<ul>
  <li><code><em>private Product readProduct() throws IOException</em></code>. 
    This<code></code> method prompts the user for input, reads product information 
    from the keyboard, and creates an instance of class <code>Product</code>. 
    The product information should consist of three values, all entered on the 
    same line, and delimited by an underscore ( <code>_</code> ). The first value 
    should be a non-empty string that represents the name of the product. The 
    second value should be a positive integer that represents the quantity of 
    product. The third value should be a positive double that represents the price. 
    Use <a href="http://java.sun.com/j2se/1.5/docs/api/java/util/StringTokenizer.html" target="externalWindow">java.util.StringTokenizer</a> 
    to extract the three values from the input. </li>
</ul>
<blockquote>
  <p><code>readProduct</code> validates the user's input:</p>
</blockquote>
<ol>
  <blockquote> 
    <ul>
      <li>If the user enters more than three values, an error message is displayed.</li>
      <li>If the user enters fewer than three values, an error message is displayed.</li>
      <li>If the user enters a quantity that is not a valid integer, <a href="http://java.sun.com/j2se/1.5/docs/api/java/lang/NumberFormatException.html" target="externalWindow">java.lang.NumberFormatException</a> 
        is caught and output.</li>
      <li>If the user enters a price that is not a valid double, <a href="http://java.sun.com/j2se/1.5/docs/api/java/lang/NumberFormatException.html" target="externalWindow">java.lang.NumberFormatException</a> 
        is caught and output.</li>
      <li> If the user enters a quantity that is negative or zero, an error message 
        is displayed.</li>
      <li>If the user enters a price that is negative, an error message 
        is displayed.</li>
    </ul>
  </blockquote>
</ol>
<blockquote> 
  <p>The error messages displayed by your implementation should match the error 
    messages displayed by the sample executable.</p>
  <p>If the input is invalid, <code>readProduct</code> re-prompts the user for 
    new input. Otherwise, it creates a new <code>Product</code> object using the 
    specified name, quantity, and price and returns a reference to the new object 
    to the calling method. </p>
</blockquote>
<h3>Submission</h3>
<p>Upon completion, submit <strong>only</strong> the following:</p>
<ol>
  <li><code><cite>ShoppingCartApplication.java</cite></code></li>
</ol>
<p><code><cite><img width="1" height="1" src="/content/SSD/SSD3/4.2.0.1/normal/pg-class-dsgn/pg-java-apps/assm-exer-read-obj-data/pool-pr-apps-io-tokenzr-excptns/qn-pr-shopping-cart/handout/resources/inherit.gif"></cite></code></p>
 </td>
<td width=5><br></td></tr></table>
<a name="9709617"></a><table><tr>
<td width=5><br></td>  <td valign=top class=td0_x align=left > <a href="#top_9709617">Go to top of question.</a> </td>
<td width=5><br></td></tr></table>
<hr><table><tr>
<td width=5><br></td>  <td valign=top class=td0_x align=left ><span class=lbl0-x>File to submit:</span><br> <input type=file class='x' name=file_to_add_9709617 value="" size=20 maxLength=500 > </td>
<td width=5><br></td><td valign=bottom>  <input class=x value="Upload File"  type=submit name=add_file id=add_file  style="width: 12em;" onClick='return SetUploadTime("https://www.icarnegie.com:443/takeassmcmd.php?question_id=9709617", 9709617, false)'></td><td width=5><br></td><td valign=bottom>  <input class=x value="Forward File"  type=submit name=mail_file id=mail_file  style="width: 12em;" onClick='return SetUploadTime("https://bjtu-cqc.icarnegie.com:443/mailuploadcmd.php?question_id=9709617", 9709617, true)'></td><td width=5><br></td><td valign=bottom>  <input class=x value="Refresh" onClick="ChangeCommand(document.Assm, 'https://www.icarnegie.com:443/refreshassmtakecmd.php?question_id=9709617')" type=submit   onfocus='ResetTarget()'></td><td width=5><br></td><td valign=bottom>  <input class=x-font value="Ready for Grading" onClick="ChangeCommand(document.Assm, 'https://www.icarnegie.com:443/takeassmcmd.php?question_id=9709617')" type=submit name=ready_for_grading id=ready_for_grading  style="width: 12em;" onfocus='ResetTarget()' disabled></td><td width=5><br></td></tr></table>
<hr><table><tr>
  <input type=hidden name="pr_state_9709617" id="pr_state_9709617" value='a:2:{i:0;s:10:&quot;incomplete&quot;;i:1;a:0:{}}' ></tr></table>
<table><tr>
<td width=5><br></td>  <td valign=top class=td0_x align=left > <a href="#top_of_page">Go to top of assessment.</a> </td>
  <input type=hidden name="max_mins_per_try" id="max_mins_per_try" value='' >  <input type=hidden name="end_date" id="end_date" value='' >  <input type=hidden name="course_section_id" id="course_section_id" value='12959222' >  <input type=hidden name="assm_id" id="assm_id" value='9709614' >  <input type=hidden name="template_id" id="template_id" value='13001876' >  <input type=hidden name="record_id" id="record_id" value='13001877' >  <input type=hidden name="client_time" id="client_time" value='' ></tr></table>
<table><tr>
<td width=5><br></td>  <td valign=top class=td0_copyright align=left > &#169; Copyright 2006 iCarnegie, Inc.  All rights reserved. </td>
</tr></table>
</form>

</body></html>

⌨️ 快捷键说明

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