📄 takeassmcmd[1].html
字号:
Observe how the program responds to the following types of input:<br>
<ul>
<li>A choice that is not an integer: <kbd>aa</kbd></li>
<li>An integer that is below the valid range: <kbd>-1</kbd></li>
<li> An integer that is above the valid range: <kbd>6</kbd></li>
<li>An integer that is within the valid range: <kbd>1</kbd>, <kbd>2</kbd>,
<kbd>3</kbd>, <kbd>4</kbd>, <kbd>5</kbd> and <kbd>0</kbd></li>
</ul>
</li>
</ol>
<ol start="3">
<li><strong>Next</strong>, complete the implementation of method <code>getChoice</code>:
<p><code><em>protected static int getChoice()</em></code>. This method displays
the following menu of options and prompts the user for a choice. </p>
<blockquote>
<pre>
0 – Quit
1 – Display name
2 – Display address
3 – Display telephone
4 – Display email
5 – Display URL
choice></pre>
</blockquote>
<p><code>getChoice</code> then reads and validates the user's input:</p>
<ul>
<li>If the user enters a choice that is not an integer, <a href="http://java.sun.com/j2se/1.5/docs/api/java/lang/NumberFormatException.html" target="externalWindow"><code>java.lang.NumberFormatException</code></a>
is caught and output.</li>
<li> If the user enters an integer outside of the valid range [0,5], an
error message is displayed. </li>
</ul>
<p>If the input is invalid, <code>getChoice</code> re-prompts the user for
a new choice. If the input is valid, <code>getChoice</code> returns the
user's choice. </p>
</li>
</ol>
<h3>Submission</h3>
<p>Upon completion, submit <strong>only</strong> the following:</p>
<ol>
<li><code><cite>ICarnegieInfoApplication.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-qz-pr-io-tokenzr/pool-pr-io-excptns/qn-pr-icarnegie-info/handout/resources/inherit.gif"></cite></code></p>
</td>
<td width=5><br></td></tr></table>
<a name="9709427"></a><table><tr>
<td width=5><br></td> <td valign=top class=td0_x align=left > <a href="#top_9709427">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_9709427 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=9709427", 9709427, 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=9709427", 9709427, 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=9709427')" 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=9709427')" 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_9709427" id="pr_state_9709427" value='a:2:{i:0;s:10:"incomplete";i:1;a:0:{}}' ><td width=5><br></td></tr></table>
<a name="top_9709432"></a><table><tr>
<td width=5><br></td> <td class=td0_highlight-label width=12 align=right valign=top nowrap >
<span class=highlight-label >2.</span></td>
<td width=5><br></td> <td valign=top class=td0_x align=left > <a href="#9709432">Go to bottom of question.</a> </td>
</tr></table>
<table><tr>
<td width=5><br></td> <td valign=top class=td0_x align=left > <!-- 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><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> <i>Exception Objects</i>
<ul>
<li>Knowledge of exception handling</li>
<li>Knowledge of <code>NumberFormatException</code></li>
</ul>
<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>
</ul>
<p> <b><i>Goals:</i></b> Reinforce your ability to use I/O classes, tokenizers,
wrapper classes, and exceptions
<p> <b><i>Outcomes:</i></b> You will master the following skills:
<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>
</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 cellpadding="2" width="75%" cellspacing="2" border="0">
<tr>
<td><img width="327" height="246" 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"></td>
</tr>
<tr>
<td><strong>Figure 1 </strong><em>Execution of SecondsCalculator</em></td>
</tr>
</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></table>
<a name="9709432"></a><table><tr>
<td width=5><br></td> <td valign=top class=td0_x align=left > <a href="#top_9709432">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_9709432 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=9709432", 9709432, 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=9709432", 9709432, 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=9709432')" 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=9709432')" 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_9709432" id="pr_state_9709432" value='a:2:{i:0;s:10:"incomplete";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='120' > <input type=hidden name="end_date" id="end_date" value='2007-10-22 08:12:33 UTC' > <input type=hidden name="course_section_id" id="course_section_id" value='12959222' > <input type=hidden name="assm_id" id="assm_id" value='9709424' > <input type=hidden name="template_id" id="template_id" value='13001868' > <input type=hidden name="record_id" id="record_id" value='13001869' > <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 > © Copyright 2006 iCarnegie, Inc. All rights reserved. </td>
</tr></table>
</form>
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -