Programming Assignment 4

Due March 17, before 9:30am

Program Description

In this assignment, you will learn about one dimensional arrays.  You will manage a list of groceries.  Each item on the list has a name, quantity, and unit price.

What You Do

It is assumed that you are using NetBeans to develop your code for this assignment.  Create a new NetBeans project that is a "General" "Java Application". Name your NetBeans project program4.

Download the source for the Main.java,
GroceryItem.java  and MyGroceryList.java classes, and store these in the program4/src/program4 directory.

Using NetBeans,
you are to implement four methods for the class MyGroceryList:
  1. public GroceryItem getItem(String name)
This method searches the list for item with matching name.  The method is case-insensitive.  Returns a reference to the matching item if one is found. Otherwise, returns null if no matching item is found,
  1. public GroceryItem getMostExpensive()
This method searches the list for the most expensive item, in terms of maximum unit cost.  Returns a reference to the most expensive item. If there are no items on the list, then this method returns null.
  1. public int getTotalCost()
This method computes (and returns) the total cost of items on the list, by multiplying unit cost for each item by quantity.   If there is no item on the list, then the method returns 0.
  1. public MyGroceryList sortAlphabeticalOrder()
This method produces a copy of the grocery list, with the items sorted in alphabetical order.  The sorting is case insensitive.  Feel free to adapt the Selection Sort algorithm given in the textbook.

Programming Style

You are expected to follow the CS111 / CS112 Java Coding Standard.  You will be graded on programming style. Each student must schedule two meetings with course staff to review a submitted program's style.   Two lab times will be set aside for this (refer to course schedule).  You can also arrange to have tutors review your program style during scheduled tutoring hours.   This is meant to allow students to get guidance and feedback on style, and the grading of style is separate from the grading of Program Assignment 4.

Testing

You are responsible for testing your methods.  To help you in testing, a few example tests are provided in the file Main.java.  Other tests will be conducted in grading -- so test your methods carefully before submitting your code. 
     

What You Submit

Submit your  file called MyGroceryList.java in a directory named 04 via gsubmit .

Under no circumstances will late assignments be accepted.

Grading Criteria



20% Submitted code compiles without errors
20% getItem
returns correct value for the cases in Main.java and at testing time.
20% getMostExpensive returns correct value for
the cases in Main.java and at testing time.
20% getTotalCost returns correct value for the cases given in Main.java and at testing time.
20% sortAlphabeticalOrder is correct for the cases given in Main.java and at testing time.