CSC212 Homework 2 2014

From dftwiki3
Revision as of 10:52, 18 September 2014 by Thiebaut (talk | contribs) (Python-Like List of Strings)
Jump to: navigation, search

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




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!
  • 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