HW1: Getting Started
Learning Objectives
This 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.
Background

A group of former JMU students have decided to open a chicken wing
delivery service called Wings-on-the-Wing. They have asked you to
create a utility class named WingPricer that they can use to
calculate the price of a particular order.
All wings are served in one or more boxes (that may be full or partially full). There are prices for full boxes of wings and prices for individual wings in partially full boxes.
Algorithms, Heuristics, Formulas, and Examples
The following algorithms, heuristics, and formulas are needed to complete this assignment. The examples should help you understand them.
Box Contents
The number of wings that fit in a full box is given by BOX_SIZE. Boxes are
filled if possible, so at most one box may be partially full.
For example, if the BOX_SIZE is 5, then an order of 98 wings will
require 19 full boxes that will hold 95 wings in total, and one
partially full box that will contain 3 wings. In other words, the
order will be served in 20 boxes total. The partially full box (if
needed) is referred to as an “extra box” and the wings in that box are
referred to as “extras”.
Pricing
The price of a full box of wings is given by PRICE_PER_BOX and the
price of an individual wing is given by PRICE_PER_INDIVIDUAL.
All flavors of wings are priced the same way. When a customer orders
less than a full box, they pay the individual price for each wing.
So, for example, if the BOX_SIZE is 5 and the PRICE_PER_INDIVIDUAL
is $1.80, an order of 3 wings will have a price of $5.40.
When a customer orders a full box, they pay the price of a full
box. So, for example, if BOX_SIZE is 10, and PRICE_PER_BOX is $14.98,
an order of 10 wings will have a price of $14.98.
Finally, when a customer orders more than a full box, they pay for the
full boxes and the extras. So, for example, if the BOX_SIZE is 10, the
PRICE_PER_BOX is $14.98, and the PRICE_PER_INDIVIDUAL is $1.00, an
order of 108 wings will have a price of $157.80 (10 boxes at $14.98
plus 8 extras at $1.00 each).
The Class to be Written
You must write the WingPricer 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).
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 number of wings and return a number (whether an
intor adouble) must return 0 when the number of wings is less than or equal to 0. (Note: There is a method that is passed a number of wings and returns aboolean. The specifications for that method are given below.) numberOfFullBoxes()andnumberOfBoxes()must return the number of full boxes and the total number of boxes required to hold the order.numberOfExtras()must return the number of wings in the order that will be in a box that isn’t full. This method may return 0.needAnExtraBox()must returntrueif there are extra wings in the order and must returnfalseotherwise. This method must not use anifstatement, loop, or ternary operator.priceFor()must return the price of an order of the given size.- 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 WingPricer class has already been written. It is named
WingPricerTest and the source code (i.e., the .java file) is
available at:
You may notice that this class does not conform to the course style guide. Most organizations (including most faculty in the Computer Science Department at JMU) allow tests to violate style guide. This policy makes it a little less onerous to write tests. To that end, your tests for this course need not comply with the course style guide. However, you are responsible for knowing the policy in place for other courses.
Submission
You must submit (using Gradescope):
- Your implementation of the
WingPricerclass. Do not include theWingPricerTestclass.
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 are unable to
complete the WingPricer class your submission should include a
stubbed-out version of all of the methods. This will allow you to
potentially get credit for the methods that you do implement.
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
hwsunder theCS159/hwsdirectory/folder. - Download
WingPricerTest.javato thehw1directory/folder.
Understand the Test Cases
- Read and understand the test cases in
WingPricerTest.java. - By hand (i.e., using pencil and paper), calculate the expected answer for each of the test cases in
WingPricerTest.java.
Stub-Out WingPricer.java
- Create a version of the
WingPricerclass that contains all of the methods (with appropriate signatures), each of which should return0,0.0, orfalseas appropriate. - Add the “javadoc” comments to the
WingPricerclass and the methods in it.- Help on “javadoc” comments is available on the Department’s Wiki.
- Additional Javadoc Guidelines are available on this site.
- Check the style of the
WingPricerclass and make any necessary corrections.
Check WingPricerTest.java
- Make sure there are no compile-time errors in
WingPricerTest.java. If there are, you probably need to fix the stubbed-out version ofWingPricer.java(since there should be no syntax errors inWingPricerTest.java).
Implement and Test the WingPricer Class
- Add the “constants”.
- Implement the
numberOfFullBoxes()method. - Run the
WingPricerTestclass and make sure that all of the answers returned by thenumberOfFullBoxes()method are correct. - Debug
numberOfFullBoxes()if necessary. - Implement the
numberOfExtras()method. - Run the
WingPricerTestclass and make sure that all of the answers returned by thenumberOfExtras()method are correct. - Debug
numberOfExtras()if necessary. - Implement the
needAnExtraBox()method. - Run the
WingPricerTestclass and make sure that all of the answers returned by theneedAnExtraBox()method are correct. - Debug
needAnExtraBox()if necessary. - Implement the
numberOfBoxes()method. - Run the
WingPricerTestclass and make sure that all of the answers returned by thenumberOfBoxes()method are correct. - Debug
numberOfBoxes()if necessary. - Implement the
priceFor()method. - Run the
WingPricerTestclass and make sure that all of the answers returned by thepriceFor()method are correct. - Debug
priceFor()if necessary.
Given the number of steps in this process, you may think that using it will slow you down. However, exactly the opposite is true. Implementing, testing, and debugging one (small) piece of code at a time has been shown to be the most efficient process.
Help
You may find the following helpful while completing this assignment.
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
WingPricer.javaif you make the attributes non-static? Why? - What compile-time errors (if any) do you get in
WingPricer.javaif you make all of the methods non-static? Why? - What compile-time errors (if any) do you get in
WingPricerTest.javaif you make the methods inWingPricer.javanon-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
numberOfBoxes()after it has you implementnumberOfExtraBoxes()andneedAnExtraBox()?