lab05 : Sorting

num ready? description assigned due
lab05 true Sorting Thu 10/25 04:00PM Fri 11/02 11:59PM

You will need to read this article first in order to know how to do this lab: https://ucsb-cs56-pconrad.github.io/topics/java_sorting/ Some of that will be review from the text, but there is also some new information; particularly about using lambda functions to sort.

In this lab:

Step-by-Step

Step 0: Set up your repo

Create your repo the same way you did for lab01, lab02, and lab04

Clone this empty repo into your ~/cs56 directory, or wherever you prefer to work.

You’ll use your lab04 repo as your starter code.

To add the starter as a remote, cd into the repo you cloned, then do:

git remote add starter git-url-of-repo-from-lab04

Then do:

git pull starter master
git push origin master

That should get your repo for lab05 set up with a copy of your repo from lab04.

Step 1: Copy code for a new class and a new set of tests into your repo.

Though there is starter code for this week, it is not a full repo; instead it is just two files that you need to copy to their proper spots. In that repo, https://github.com/ucsb-cs56-f18/STARTER_lab05, you’ll find these files:

File Where to copy it in your lab05 repo
Menu.java src/main/java/edu/ucsb/cs56/pconrad/menuitems
MenuTest.java src/test/java/edu/ucsb/cs56/pconrad/menuitems

To copy these to their proper spots, you could do any of the following. How you get the file there is up to you. At this point, you will be expected to have the skills to do that, but if you need some suggestions, here you go:

  1. Clone this repo to another directory (not inside of your lab05 repo directory, but as a sibling, for example). Then use the Unix cp or mv file to copy the file into it’s proper spot.
  2. Use the “raw” tab on the github site to expose a version of the file that doesn’t have any extra formatting (line numbers, etc.). Then any of the following techniques:
    • Use “save as” in your web browser to save a copy into the correct directory
    • Copy the URL, then cd into the target directory, and use wget url to get the file.
    • Open the target filename in an editor as an empty file, and use copy/paste to paste in the contents.

Step 2: Start writing code to make tests pass

In the previous lab, lab04, you implemented several methods of a class called MenuItem that represents item on a restaurant Menu. Now, we will implement the Menu class. The details about the Menu class appear below.

Ideally, we’d need to discuss sorting, java.lang.Comparable, java.util.Comparator, and Java lambda expressions in lecture first; instead, here is a link to some materials you can read to learn what you need to know:

Just like last week, note that the starter code:

I suggest that you work in this order:

Details about methods of Menu

The methods for Menu are as follows:

Modifier and Type Method Description
void add(MenuItem mi) add a menu item to the menu (to the wrapped ArrayList<MenuItem>)  
String csv() Produce a listing of each item in csv format, with newlines between each item. Order is whatever order the items are currently in the ArrayList
String csvSortedByName() same as csv(), but the items should be sorted in lexicographic order by name.
String csvSortedByCategoryThenName() same as csv(), but the items should be sorted by category. With the same category, the items should be sorted by name.
String csvSortedByCategoryThenPriceDescendingThenByName() same as csv(), but the items should be sorted by category. With the same category, the items should be sorted by name.
String csvSortedByPriceThenName() same as csv(), but the items should be sorted by price, from lowest to highest. When more than one items has the same price, the items of the same price should be sorted by name.

Step 3: Checking Test Case Coverage

As you did last week, be sure that you’ve added your pair partner to your submissions on Gauchospace

Then, check your test coverage:

Some of the points in the manual inspection may be awarded on the basis of having good test coverage.
While 100% test coverage is not always the goal, in this particular exercise, it should be possible.

So if you see that you don’t have 100% test coverage, go back and write some additional unit tests.

For a review of how to read the test coverage reports provided by Jacoco, see: https://ucsb-cs56-pconrad.github.io/topics/testing_jacoco_reports/

End of description for lab05