HW1: Campus Shipping v1¶
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).
Detailed Design Specifications¶
In addition to the specifications contained in the UML class diagram, this class must conform to the following specifications.
- All of the "constants" must be declared to be final.
- All of the methods that are passed a shipment size and return a number (whether an
int
or adouble
) must return0
when the shipment size is less than or equal to 0. - All of the methods that are passed a shipment size and return a
boolean
must returnfalse
when the shipment size is less than or equal to 0. numberOfCompletePallets()
andnumberOfPallets()
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.involvesPartialPallet()
must returntrue
if the shipment requires a partial pallet and must return false otherwise. This method must not use anif
statement, loop, or ternary operator.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.- 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:
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):
- A
.zip
file containing the directory/folderhw1
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.
Recommended Process¶
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¶
- Read and understand the entire assignment.
- Create a directory/folder for this assignment named
hw1
under the directory/folder namedCS159/src
. - Download
BookShippingTest.java
(e.g., to thedownloads
directory you created for this course) but do not move it tohw1
.
Understand the Test Cases¶
- Read and understand the test cases in
BookShippingTest.java
. - Think about why each test case was included.
- 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
¶
- Create a version of the
BookShippingCostCalculator
class that contains all of the methods (with appropriate signatures), each of which should return0
,0.0
, orfalse
as appropriate. - Add the "javadoc" comments to the
BookShippingCostCalculator
class and the methods in it. (Help on "javadoc" comments is available on the Department's Wiki.) - Check the style of the
BookShippingCostCalculator
class and make any necessary corrections.
Add BookShippingTest.java
to the hw1
Directory/Folder¶
- Move
BookShippingTest.java
to thehw1
directory/folder. - Make sure there are no compile-time errors in
BookShippingTest.java
. If there are, you probably need to fix the stubbed-out version ofBookShippingCostCalculator.java
(since there should be no syntax errors inBookShippingTest.java
).
Implement and Test the BookShippingCostCalculator
Class¶
- Add the "constants".
- Add the
numberOfCompletePallets()
method. - Run the
BookShippingTest
class and make sure that all of the answers returned by thenumberOfCompletePallets()
method are correct. - Debug
numberOfCompletePallets()
if necessary. - Add the
involvesPartialPallets()
method. - Run the
BookShippingTest
class and make sure that all of the answers returned by theinvolvesPartialPallets()
method are correct. - Debug
involvesPartialPallets()
if necessary. - Add the
numberOfPallets()
method. - Run the
BookShippingTest
class and make sure that all of the answers returned by thenumberOfPallets()
method are correct. - Debug
numberOfPallets()
if necessary. - Add the
cost()
method. - Run the
BookShippingTest
class and make sure that all of the answers returned by thecost()
method are correct. - 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.
- What compile-time errors (if any) do you get in
BookShippingCostCalculator.java
class if you make the attributes non-static? Why? - What compile time errors (if any) do you get in
BookShippingCostCalculator.java
if you make all of the methods non-static? Why? - What compile-time errors (if any) do you get in
BookShippingTest.java
if you make the methods inBookShippingCostCalculator.java
non-static? Why? - Why does the recommended process have you test and debug each method immediately after you implement it?
- 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 implementinvolvesPartialPallet()
? - Why isn't
involvesPartialPallet()
namedinvolvesPartialPallets()
?