?? pq1.html
字號(hào):
<ol>
<li><code><cite>ICarnegieInfoApplication.java</cite></code></li>
</ol>
<p><code><cite><img src="/content/SSD/SSD3/4.2.0.1/normal/pg-class-dsgn/pg-java-apps/assm-qz-pr-io-tokenzr/pool-pr-io-excptns/qn-pr-icarnegie-info/handout/resources/inherit.gif" height="1" width="1"></cite></code></p>
</td>
<td width="5"><br></td></tr></tbody></table>
<a name="13639"></a><table><tbody><tr>
<td width="5"><br></td> <td class="td0_x" align="left" valign="top"> <a href="#top_13639">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_13639">File to submit:</label><br> <input class="x" name="file_to_add_13639" 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=13639", 13639, false)' type="submit"></td><td width="5"><br></td></tr></tbody></table>
<hr><input name="pr_state_13639" id="pr_state_13639" value="a:2:{i:0;s:10:"incomplete";i:1;a:0:{}}" type="hidden"><table><tbody><tr>
<td width="5"><br></td></tr></tbody></table>
<a name="top_13644"></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">2.</label></td>
<td width="5"><br></td> <td class="td0_x" align="left" valign="top"> <a href="#13644">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"><cite>SecondsCalculator</cite></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 Language</em>
<ul>
<li>Knowledge of Java control structures</li>
</ul>
</li><li><i>Java API</i>
<ul>
<li>Knowledge of package <code>java.io</code>
<ul>
<li>How to get input from the keyboard</li>
<li>How to output results, prompts, and errors</li>
</ul>
</li>
<li>Knowledge of wrapper class <code>Integer</code>: how to read an integer
value as input</li>
<li>Knowledge of class <code>StringTokenizer</code>: how to parse a line
with multiple values</li>
</ul>
</li><li> <i>Exception Objects</i>
<ul>
<li>Knowledge of exception handling</li>
<li>Knowledge of <code>NumberFormatException</code></li>
</ul>
</li><li><i>Programming Practice</i>
<ul>
<li>How to produce Java applications</li>
<li>Knowledge of Sun's code conventions</li>
</ul>
<ul>
<li>Knowledge of Javadoc: how to document classes, methods, and variables</li>
</ul>
</li></ul>
<p> <b><i>Goals:</i></b> Reinforce your ability to use I/O classes, tokenizers,
wrapper classes, and exceptions
</p><p> <b><i>Outcomes:</i></b> You will master the following skills:
</p><ul>
<li> Produce an application that reads input from the keyboard and uses:
<ul>
<li>Wrapper classes to read numerical data</li>
<li><code>StringTokenizer</code> to parse a line with multiple values</li>
<li>Exceptions to handle malformed data</li>
<li>Control structures to control the reading of data</li>
</ul>
</li></ul>
</blockquote>
<h3>Background </h3>
<p> This assignment asks you to construct a simple application that processes
a line of text that contains multiple values. Your application will read a time
interval expressed in hours, minutes, and seconds from the keyboard and then
display the total number of seconds in the specified time interval. Your application
will consist of one class called <code>SecondsCalculator</code>.</p>
<h3>Description</h3>
<p><code>SecondsCalculator</code> reads, from the keyboard, three integers entered
on the same line and separated by a colon ( : ). The first integer represents
the hours, the second represents the minutes, and the third represents the seconds.</p>
<p> If the user enters a non-integer, or an integer outside of the valid range,
the application displays an error message. Either way, the user is re-prompted
for new input. </p>
<p>If the input is valid, the application displays the total number of seconds
the specified time interval. The total number of seconds for time interval <em>hours:minutes:seconds</em>
is computed using the following expression:</p>
<blockquote> <em>hours</em> * 3600 + <em>minutes</em> * 60 +<em> seconds</em></blockquote>
<p>The following is a screen shot of the application.</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-dsgn/pg-java-apps/assm-qz-pr-io-tokenzr/pool-pr-io-tokenzr-excptns/qn-pr-seconds-calculator/handout/images/seconds-calculator-execution.jpg" alt="Figure 1 Execution of SecondsCalculator" height="246" width="327"></td>
</tr>
<tr>
<td><strong>Figure 1 </strong><em>Execution of SecondsCalculator</em></td>
</tr>
</tbody></table>
</blockquote>
<h3>Files</h3>
<p>The following files are needed to complete this assignment:</p>
<ul>
<li><cite><a href="/content/SSD/SSD3/4.2.0.1/normal/pg-class-dsgn/pg-java-apps/assm-qz-pr-io-tokenzr/pool-pr-io-tokenzr-excptns/qn-pr-seconds-calculator/handout/exe-seconds-calculator.jar">exe-seconds-calculator.jar</a></cite>.
Download this file. It is a sample executable.</li>
</ul>
<h3>Tasks </h3>
<p>To complete this assignment, you will implement class <code>SecondsCalculator</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>Run</strong> the sample executable by issuing the following command
at the command prompt:
<blockquote><tt>C:\></tt><kbd>java -jar exe-seconds-calculator.jar</kbd>
</blockquote>
<p>Observe how the application responds to the following types of input:</p>
<ul>
<li>Input with a value that is not an integer: <kbd>1.0:1:1</kbd>, <kbd>1:1.0:1</kbd>,
or <kbd>1:1:1.0</kbd>.</li>
<li> Input with an integer outside of a valid range: <kbd>24:1:1</kbd>,
<kbd>1:60:1</kbd>, <kbd>1:1:60</kbd>, <kbd>-1:1</kbd>, <kbd>1:-1:1</kbd>,
or <kbd>1:1:-1</kbd>.</li>
<li>Input that contains more than three integers: <kbd>1:1:1:1</kbd>.</li>
<li>Input that contains fewer than three integers: <kbd>1:1</kbd>.</li>
<li>Valid input: <kbd>0:0:0</kbd>, <kbd></kbd><kbd>1:1:1</kbd>, or <kbd></kbd><kbd>23:59:59</kbd>.</li>
</ul>
</li>
</ol>
<ol start="2">
<li><strong>Then</strong>, write this application from scratch: The application
reads, from the keyboard, three integers entered on the same line and separated
by a colon (<code>:</code>). 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 hours, minutes, and seconds from the input. The first integer
represents the hours and should be confined to the range [0,23]; the second
integer represents the minutes and should be confined to the range [0,59];
and the third integer represents the seconds and should be confined to the
range [0,59].
<p> The application validates the user's input:</p>
<ul>
<li>If the user enters fewer than three values, an error message is displayed.</li>
<li>If the user enters more than three values, an error message is displayed.</li>
<li>If the user enters a value that is not an 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 displayed.</li>
<li> If the user enters an integer outside the valid range, an error message
is displayed. </li>
</ul>
<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, the application re-prompts the user for new input.
If the input is valid, the application displays the total number of seconds
in the specified time interval.</p>
</li>
</ol>
<h3>Submission</h3>
<p>Upon completion, submit <strong>only</strong> the following:</p>
<ol>
<li><code><cite>SecondsCalculator.java</cite></code></li>
</ol> </td>
<td width="5"><br></td></tr></tbody></table>
<a name="13644"></a><table><tbody><tr>
<td width="5"><br></td> <td class="td0_x" align="left" valign="top"> <a href="#top_13644">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_13644">File to submit:</label><br> <input class="x" name="file_to_add_13644" 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=13644", 13644, false)' type="submit"></td><td width="5"><br></td></tr></tbody></table>
<hr><input name="pr_state_13644" id="pr_state_13644" 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:33:43 UTC" id="end_date" name="end_date" type="hidden"> <input value="421063" id="course_section_id" name="course_section_id" type="hidden"> <input value="13636" id="assm_id" name="assm_id" type="hidden"> <input value="657482" id="template_id" name="template_id" type="hidden"> <input value="657483" 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.
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -