📄 pq7.html
字号:
<span class="dialogueheader">Take Assessment: Practical Quiz 7</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="657624" 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:45:36 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:45:36 GMT+0800.</td> <td width="5"><br></td></tr></tbody></table>
<a name="top_14344"></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="#14344">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">
<center>
<h2>Using Java Collections</h2>
</center>
<h3>Prerequisites, Goals, and Outcomes</h3>
<blockquote> <b><i>Prerequisites:</i></b> Before you begin this exercise, you
need:
<ul>
<li><em> Java collections</em>
<ul>
<li>Knowledge of class <code>ArrayList</code>
<ul>
<li>Declaring array lists</li>
<li>Initializing array lists</li>
<li>Accessing array list elements </li>
<li>Adding elements to an array list</li>
<li>Removing elements from an array list</li>
</ul>
</li>
</ul>
</li></ul>
<ul>
<li> <em>Iterators and <code>for-each</code> loop</em>:
<ul>
<li>Know how to traverse and manipulate a collection using iterators and <code>for-each</code> loops.</li>
</ul>
</li></ul>
<p> <b><i>Goals:</i></b> Reinforce your ability to use class <code>ArrayList</code>, iterators
and <code>for-each</code> loops.
</p><p> <b><i>Outcomes:</i></b> You will demonstrate mastery of the following:
</p><ul>
<li>Using Java collections
<ul>
<li>Creating a collection:
<ul>
<li>From a set of objects </li>
<li>From an array</li>
</ul>
</li>
</ul>
</li>
</ul>
</blockquote>
<blockquote>
<ul>
<ul>
<li>Processing collections</li>
</ul>
<ul>
<ul>
<li>Finding an element with a specific characteristic </li>
<li>Counting the number of elements with a specific characteristic</li>
<li>Analyzing the contents of a collection
<p></p>
</li>
</ul>
<li>Removing elements from a collection:
<ul>
<li>Removing all objects with a specific characteristic </li>
</ul>
</li>
</ul>
</ul>
</blockquote>
<blockquote>
<ul>
<ul>
<li>Displaying the contents of a collection
<ul>
<li>Obtaining the string representation of a collection</li>
</ul>
</li>
</ul>
</ul>
</blockquote>
<h3>Background </h3>
<p> This assignment asks you to implement a set of methods to
process Java collections.<b></b></p>
<b>
<h3>Description</h3>
</b>
<p>In this assignment, you will finish the implementation of <code>StudentArrayList</code>, a class with methods for processing an <a href="http://java.sun.com/j2se/1.5/docs/api/java/util/ArrayList.html" target="externalWindow"><code><em>ArrayList</em></code></a> of <code>Student</code> objects. iCarnegie provides
a test driver and the class <code>Student</code>.</p>
<h4>Class <code>Student</code></h4>
<p>A complete implementation of this class is included in the student archive <cite><a href="/content/SSD/SSD3/4.2.0.1/normal/pg-class-imp/pg-collctns/assm-qz-pr-java-collctns/pool-pr-java-collctns/qn-pr-java-collctns/handout/student-files.zip"><code>student-files.zip</code></a></cite>.
Stop <em>now</em> and review its documentation:</p>
<ul>
<li><a href="/content/SSD/SSD3/4.2.0.1/normal/pg-class-imp/pg-collctns/assm-qz-pr-java-collctns/pool-pr-java-collctns/qn-pr-java-collctns/handout/Student.html" target="externalWindow"><code><em>Student.html</em></code></a>.
Documentation of class <code>Student</code></li>
</ul>
<h4>Class <code>StudentArrayList</code></h4>
<p>A partial implementation of this class is included in
the student archive <cite><a href="/content/SSD/SSD3/4.2.0.1/normal/pg-class-imp/pg-collctns/assm-qz-pr-java-collctns/pool-pr-java-collctns/qn-pr-java-collctns/handout/student-files.zip"><code>student-files.zip</code></a></cite>.
You should complete the implementation of each method. </p>
<h4>Class <code>TestStudentArrayList</code></h4>
<p>This class is a test driver for class <code>StudentArrayList</code>.
It contains test cases for each method in the class. A complete implementation
is included in the student archive
<cite><a href="/content/SSD/SSD3/4.2.0.1/normal/pg-class-imp/pg-collctns/assm-qz-pr-java-collctns/pool-pr-java-collctns/qn-pr-java-collctns/handout/student-files.zip"><code>student-files.zip</code></a></cite>.
You should use this class to test your implementation of class <code>StudentArrayList</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-class-imp/pg-collctns/assm-qz-pr-java-collctns/pool-pr-java-collctns/qn-pr-java-collctns/handout/student-files.zip"><code>student-files.zip</code></a></cite>.
Download this file. This archive contains the following:
<ul>
<li><cite><code>Student.java</code></cite>. A complete implementation</li>
<li> <cite><code>StudentArrayList.java</code></cite>. Use this template to
complete your implementation.</li>
<li><cite><code>Test</code></cite><cite><code>StudentArrayList.java</code></cite>.
A complete implementation</li>
</ul>
</li>
</ul>
<h3>Tasks </h3>
<p> Implement all methods in class <code>StudentArrayList</code>. 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>Test</strong> each method as soon as you finish writing it by issuing
the following command at the command prompt:
<p><tt>C:\></tt><kbd>java TestStudentArrayList</kbd></p>
</li>
</ol>
<ol start="3">
<li><strong> Implement</strong> the method <code>makeArrayList</code>:</li>
</ol>
<ul>
<li><code><em>public static ArrayList<Student> makeArrayList(Student first, Student second,
Student third)</em></code>. This method takes three <code>Student</code> objects
and returns an array list with three elements. The first element of the array list
contains a reference to the first argument; the second element contains a
reference to the second argument; and the third element contains a reference
to the third argument.</li>
</ul>
<blockquote>
<p>For example, consider the following three <code>Student</code> objects:</p>
<ul>
<li><code>Student[328,Galileo Galilei,80]</code></li>
<li><code>Student[123,Albert Einstein,100]</code></li>
<li><code>Student[96,Isaac Newton,90]</code></li>
</ul>
<p>If these objects are passed to <code>makeArrayList</code> in the indicated order,
<code>makeArrayList</code> will return an array list with three <code>Student</code> objects:</p>
<pre> ArrayList{Student[328,Galileo Galilei,80],
Student[123,Albert Einstein,100],
Student[96,Isaac Newton,90]}</pre>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -