Difference between revisions of "CSC212 Homework 2 2014"
(→Submission to Moodle) |
|||
(8 intermediate revisions by the same user not shown) | |||
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> | ||
Line 18: | Line 19: | ||
<br /> | <br /> | ||
* Take the Python-Like list from [[CSC212_Lab_4_2014#Emulating_a_Python_List | Lab #4]]. Call your program '''PythonList.java''' | * Take the Python-Like list from [[CSC212_Lab_4_2014#Emulating_a_Python_List | 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. | * Make all of its member variables private. | ||
− | * Create accessors, mutators, and other methods that | + | * Create accessors, mutators, and other methods that will be helpful to whomever is going to use your list. |
* Test your class thoroughly. | * Test your class thoroughly. | ||
− | * Create | + | * 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 |
<br /> | <br /> | ||
::<source lang="java"> | ::<source lang="java"> | ||
Line 28: | Line 30: | ||
</source> | </source> | ||
− | :and will compute the 8th row of Pascal's triangle using A. | + | :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. |
<br /> | <br /> | ||
+ | Your program should just compute the 8th row, and output it, one number per line, as you did in Homework 1. | ||
+ | |||
==Submission to Moodle== | ==Submission to Moodle== | ||
<br /> | <br /> | ||
− | * | + | * Go to Moodle, locate the "Hw 2: Pascal Triangle with a Python-Like list" link, and submit your programs. You have to submit both '''PascalList.java''' and '''PythonList.java'''. |
+ | |||
<br /> | <br /> | ||
<br /> | <br /> | ||
+ | |||
=Python-Like List of Strings= | =Python-Like List of Strings= | ||
<br /> | <br /> | ||
Line 45: | Line 51: | ||
* It will be tested with the following main program in a different class: | * It will be tested with the following main program in a different class: | ||
<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 --- | ||
− | PythonList2 dwarves = new PythonList2( | + | PythonList2 dwarves = new PythonList2(5); |
dwarves.append("Blick"); | dwarves.append("Blick"); | ||
Line 89: | Line 96: | ||
} | } | ||
+ | } | ||
</source> | </source> | ||
<br /> | <br /> | ||
Line 108: | Line 116: | ||
<br /> | <br /> | ||
<br /> | <br /> | ||
+ | |||
==Submission to Moodle== | ==Submission to Moodle== | ||
<br /> | <br /> | ||
− | * | + | * Go to Moodle and Locate the VPL Test "'''Hw2: Python-Like List of String'''". |
+ | * Submit your program to this module for automatic grading. | ||
<br /> | <br /> | ||
<br /> | <br /> |
Latest revision as of 13:16, 19 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
- 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
- Go to Moodle, locate the "Hw 2: Pascal Triangle with a Python-Like list" link, and submit your programs. You have to submit both PascalList.java and PythonList.java.
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(5); 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
- Go to Moodle and Locate the VPL Test "Hw2: Python-Like List of String".
- Submit your program to this module for automatic grading.