Difference between revisions of "CSC212 Homework 2 2014"

From dftwiki3
Jump to: navigation, search
(Your Assignment)
(Test)
Line 50: Line 50:
 
<br />
 
<br />
 
<source lang="java">
 
<source lang="java">
 +
class TestPythonList2 {
 
         public static void main(String[] args) {
 
         public static void main(String[] args) {
 
// --- Test List ---
 
// --- Test List ---
Line 93: Line 94:
  
 
}
 
}
 +
}
 
</source>
 
</source>
 
<br />
 
<br />
Line 112: Line 114:
 
<br />
 
<br />
 
<br />
 
<br />
 +
 
==Submission to Moodle==
 
==Submission to Moodle==
 
<br />
 
<br />

Revision as of 12:07, 18 September 2014

--D. Thiebaut (talk) 07:54, 18 September 2014 (EDT)




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
  • Keep it as a class implementing a list of integers (Problem 2 will deal with strings).
  • Make all of its member variables private.
  • Create accessors, mutators, and other methods that will be helpful to whomever is going to use your list.
  • Test your class thoroughly.
  • Create a new class called PascalList.java', which, instead of using an array to compute the 8th row of Pascal's triangle, will use an object instantiated from your PythonList class. 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, and only A. Note that PythonList.java can use an other array of ints internally to do some of its work.


Your program should just compute the 8th row, and output it, one number per line, as you did in Homework 1.

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:


class TestPythonList2 {
        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!