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. However, we did not have object orientation at the time this project was given, so you should not solve it in an object-oriented way (that would obviate some of the method techniques you need to show me you can do).

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 method to do it. It is fine to break tasks into extra methods (with parameters/return), just as it is fine to add extra local variables. However, if I specify the name, parameters, or return for a method, then that method should just have those characteristics.

Assume that arrays are passed as parameters 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. (Of course you can also choose to return an array from a method if you need to)

In a .txt document write pseudocode for the following:


Part A

[30] Write a method shrinkArray that takes an array of ints and returns an array of ints. In the method, 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}.

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


Part B

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