Difference between revisions of "CSC212 Homework 2 2014"
Line 6: | Line 6: | ||
<bluebox> | <bluebox> | ||
+ | This assignment is for you to explore all the coding that is somehow hidden in the Python List. We haven't formally seen List, which is a main data-structure for us to explore. We'll do that formally soon. But in the mean time, this assignment will help you understand what a data structure is, and why it is useful to build it a particular way.<br /> | ||
This assignment is due Thursday, Sept. 25, at 11:55 p.m. | This assignment is due Thursday, Sept. 25, at 11:55 p.m. | ||
</bluebox> | </bluebox> |
Revision as of 12:03, 18 September 2014
--D. Thiebaut (talk) 07:54, 18 September 2014 (EDT)
Contents
This assignment is for you to explore all the coding that is somehow hidden in the Python List. We haven't formally seen List, which is a main data-structure for us to explore. We'll do that formally soon. But in the mean time, this assignment will help you understand what a data structure is, and why it is useful to build it a particular way.
This assignment is due Thursday, Sept. 25, at 11:55 p.m.
Python-Like List
Your Assignment
- Take the Python-Like list from Lab #4. Call your program PythonList.java
- Make all of its member variables private.
- Create accessors, mutators, and other methods that you see fit to add for the purpose of this assignment.
- Test your class thoroughly.
- Create another class called PascalList.java, which, instead of using an array to compute the 8th row of Pascal's triangle, will your an object instantiated from PythonList. In other words, your PascalList program will declare
PythonList A = new PythonList( 10 );
- and will compute the 8th row of Pascal's triangle using A.
Submission to Moodle
- The Moodle test will be provided at a later time... Please stay tuned!
Python-Like List of Strings
- Create a new version of PythonList.java called PythonList2.java.
- Modify it so that the list can now hold strings.
- Test it thoroughly!
Test
- It will be tested with the following main program in a different class:
public static void main(String[] args) {
// --- Test List ---
PythonList2 dwarves = new PythonList2(10);
dwarves.append("Blick");
dwarves.append("Flick");
dwarves.append("Glick");
dwarves.append("Plick");
dwarves.append("Quee");
dwarves.append("Snick");
dwarves.append("Whick");
System.out.println("Snow White's friends:");
for (int i = 0; i < dwarves.length(); i++)
System.out.println(dwarves.at(i));
String dwarf;
dwarf = dwarves.at(-1);
if (dwarf != null)
System.out.println(dwarf);
dwarf = dwarves.at(20);
if (dwarf != null)
System.out.println(dwarf);
int n = dwarves.index( "Quee" );
if ( n != -1 )
System.out.println( "Quee found at Index: " + n );
else
System.out.println( "Quee not found" );
n = dwarves.rindex( "Quee" );
if ( n != -1 )
System.out.println( "Quee found at Index: " + n );
else
System.out.println( "Quee not found" );
n = dwarves.index( "Queen" );
if ( n != -1 )
System.out.println( "Queen found at Index: " + n );
else
System.out.println( "Queen not found" );
}
- The output of the main program above, when it uses your PythonList2, should be:
Snow White's friends: Blick Flick Glick Plick Quee Snick Whick Quee found at Index: 4 Quee found at Index: 4 Queen not found
Submission to Moodle
- The Moodle test will be provided at a later time... Please stay tuned!