Skip to content

HW1: Campus Shipping v1

Campus Shipping Logo

Learning Objectives

This homework assignment is designed to help you learn several things. First, it will help you learn about data types, variables, literals, arithmetic operators, how utility classes are organized, static attributes, and declaring static methods. Second, it will help you become comfortable with some of the tools that you will be using throughout the semester. Third, it will help you become comfortable with the various policies (including submission policies) that you must comply with while working on homework assignments and programming assignments this semester.

Overview

A group of former JMU students have decided to open a shipping/delivery service called Campus Shipping that will ship books to campus bookstores. They have asked you to create a utility class named BookShippingCostCalculator that they can use to calculate the cost of shipping a particular order. The books are shipped on pallets that may be complete (i.e., full) or partially complete (i.e., there is space remaining). The cost of shipping is based on the amount of floor space in the truck that is used (which is based on the number of pallets) and the total weight of the shipment.

The number of books that fit on a full pallet is given by BOOKS_PER_PALLET. The cost of shipping a pallet (full or otherwise) is given by COST_PER_PALLET. All books are assumed to have the same weight, which is given by POUNDS_PER_BOOK. The cost of shipping a pound of books is given by COST_PER_POUND.

The Class to be Written

You must write the BookShippingCostCalculator class.

The UML Class Diagram

The following UML class diagram provides an overview of the attributes and methods in this class (which must be in the hw1 package, even though that is not shown in the UML class diagram).

Class Diagram

Detailed Design Specifications

In addition to the specifications contained in the UML class diagram, this class must conform to the following specifications.

  1. All of the "constants" must be declared to be final.
  2. All of the methods that are passed a shipment size and return a number (whether an int or a double) must return 0 when the shipment size is less than or equal to 0.
  3. All of the methods that are passed a shipment size and return a boolean must return false when the shipment size is less than or equal to 0.
  4. numberOfCompletePallets() and numberOfPallets() must return the number of complete (i.e., full) pallets and the total number of pallets (partial plus complete) required to hold a particular shipment, respectively. So, for example, an order of 41 books will require 1 complete pallet and 2 pallets in total.
  5. involvesPartialPallet() must return true if the shipment requires a partial pallet and must return false otherwise. This method must not use an if statement, loop, or ternary operator.
  6. cost() must return the cost of a particular shipment. For example, a shipment of 41 books will require two pallets (at a cost of $85.00 each) and will weigh 90.20 pounds (at a cost of $1.50 per pound), for a total cost of $305.30.
  7. Methods must not duplicate the code in other methods unless it is absolutely necessary (e.g., for parameter validation). Instead, methods must invoke each other as needed.

An Existing Class

A main class (i.e., a class with a main() method) that you can use to test the BookShippingCostCalculator class has already been written. It is named BookShippingTest and the source code (i.e., the .java file) is available at:

BookShippingTest.java

Info

You may notice that this class does not conform to the style guide. Most organizations (including most faculty in the Computer Science Department at JMU) do not require that tests conform to the style guide. To accommodate this, classes that are used for testing must start or end with Test.

Submission

You must submit (using Gradescope):

  1. A .zip file containing the directory/folder hw1 at the top-level.

There is no limit on the number of submissions and no penalty for excessive submissions. Note that your submission will not be graded if it does not comply with the specifications. So, if you do not complete the BookShippingCostCalculator class, your submission should include a stubbed-out version of all of the methods. This will allow you to get credit for the methods that you do implement correctly.

Grading

Your code will first be graded by Gradescope and then by the Professor. The grade you receive from Gradescope is the maximum grade that you can receive on the assignment

Gradescope Grading

Your code must compile (in Gradescope, this will be indicated in the section on "Does your code compile?") and all class names and method signatures must comply with the specifications (in Gradescope, this will be indicated in the section on "Do your class names, method signatures, etc. comply with the specifications?") for you to receive any points on this assignment. Gradescope will then grade your submission as follows:

Criterion Points Details
Conformance to the Style Guide 20 points (Partial Credit Possible)
Correctness 80 points (Partial Credit Possible)

Gradescope will provide you with hints, but may not completely identify the defects in your submission.

Manual Grading

After the due date, the Professor may manually review your code. At this time, points may be deducted for inelegant code, inappropriate variable names, bad comments, etc.

Since nobody will be looking over your shoulder, you can use any process that you would like to use. However, it is strongly recommended that you use the process described here.

Get Started

  1. Read and understand the entire assignment.
  2. Create a directory/folder for this assignment named hw1 under the directory/folder named CS159/src.
  3. Download BookShippingTest.java (e.g., to the downloads directory you created for this course) but do not move it to hw1.

Understand the Test Cases

  1. Read and understand the test cases in BookShippingTest.java.
  2. Think about why each test case was included.
  3. By hand (i.e., using pencil and paper), calculate the expected answer for each of the test cases in BookShippingTest.java.

Stub-Out BookShippingCostCalculator.java

  1. Create a version of the BookShippingCostCalculator class that contains all of the methods (with appropriate signatures), each of which should return 0, 0.0, or false as appropriate.
  2. Add the "javadoc" comments to the BookShippingCostCalculator class and the methods in it. (Help on "javadoc" comments is available on the Department's Wiki.)
  3. Check the style of the BookShippingCostCalculator class and make any necessary corrections.

Add BookShippingTest.java to the hw1 Directory/Folder

  1. Move BookShippingTest.java to the hw1 directory/folder.
  2. Make sure there are no compile-time errors in BookShippingTest.java. If there are, you probably need to fix the stubbed-out version of BookShippingCostCalculator.java (since there should be no syntax errors in BookShippingTest.java).

Implement and Test the BookShippingCostCalculator Class

  1. Add the "constants".
  2. Add the numberOfCompletePallets() method.
  3. Run the BookShippingTest class and make sure that all of the answers returned by the numberOfCompletePallets() method are correct.
  4. Debug numberOfCompletePallets() if necessary.
  5. Add the involvesPartialPallets() method.
  6. Run the BookShippingTest class and make sure that all of the answers returned by the involvesPartialPallets() method are correct.
  7. Debug involvesPartialPallets() if necessary.
  8. Add the numberOfPallets() method.
  9. Run the BookShippingTest class and make sure that all of the answers returned by the numberOfPallets() method are correct.
  10. Debug numberOfPallets() if necessary.
  11. Add the cost() method.
  12. Run the BookShippingTest class and make sure that all of the answers returned by the cost() method are correct.
  13. Debug cost() if necessary.

Help

You may find the following helpful while completing this assignment.

Help Creating .zip Files

The directories/folders containing the package hw1 must appear at the top of the .zip file that you submit. So, you must not compress the directory/folder containing this directory/folder (e.g., the src directory/folder or the CS159 directory folder), you must compress the hw1 directory/folder itself.

Help creating .zip files is available on the CS Department's Wiki.

Help With Gradescope

Help with Gradescope is available on the CS Department's Wiki.

Relevant Programming Patterns

An understanding of the following programming patterns will help you complete this assignment:

Questions to Think About

You don't have to submit your answers to these questions, but you should try to answer them because they will help you determine whether or not you understand some of the important concepts covered in this assignment.

  1. What compile-time errors (if any) do you get in BookShippingCostCalculator.java class if you make the attributes non-static? Why?
  2. What compile time errors (if any) do you get in BookShippingCostCalculator.java if you make all of the methods non-static? Why?
  3. What compile-time errors (if any) do you get in BookShippingTest.java if you make the methods in BookShippingCostCalculator.java non-static? Why?
  4. Why does the recommended process have you test and debug each method immediately after you implement it?
  5. Why does the recommended process have you implement the methods in the order it does? For example, why does it have you implement numberOfPallets() after it has you implement involvesPartialPallet()?
  6. Why isn't involvesPartialPallet() named involvesPartialPallets()?