Project 2

Your goal for this project is to give me as many opportunities as possible to give you credit for topics covered in the class, particularly those since the last project. You want me to at least be able to give you credit for good use of while loops, for loops, parallel arrays, firstEmpty, breaking tasks into methods, methods with parameters, and methods that return.

Remember:

Throughout this assignment you can assume that arrays know their own size. Think about where while vs for loops are appropriate. Think about where parameters vs user prompting is appropriate. Give all variables meaningful names unless they are just numbers used for counting or math. (hint: break to end a loop is usually bad coding practice, and is NOT needed for any part of this assignment)

For this project, write code to do all actions and caluclations that need to happen.  If you need something done, write a module to do it. It is fine to break tasks into extra modules (with parameters/return), just as it is fine to add extra local variables. However, if I specify the name, parameters, or return for a module, then that module should just have those characteristics.

Assume that arrays are passed as parameters using the book's version of "by reference" that is: a method is given the actual array (by address) not just a copy, so any changes it made to the array are still there after the method ends, you don't have to return it.

In a .txt document write pseudocode for the following:


Part A

[30] Write a module shrinkArray that takes an array of ints and returns an array of ints. In the module, count how many elements of the array are nonzero, make a new array of that size, copy over the non-zero elements, and return that array, so given {0,2,0,4,0,0,8,9} the method would return {2,4,8,9}.

Part B

[70] You will write a program for grocery shopping. Break it into reasonable modules and have a main to start the program.


Extra Credit +25 In addition to the pseudocode version, write a working Java version of part B.