Skip to content

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

Wings-on-the-Wing Logo

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).

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 number of wings and return a number (whether an int or a double) 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 a boolean. The specifications for that method are given below.)
  3. numberOfFullBoxes() and numberOfBoxes() must return the number of full boxes and the total number of boxes required to hold the order.
  4. 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.
  5. needAnExtraBox() must return true if there are extra wings in the order and must return false otherwise. This method must not use an if statement, loop, or ternary operator.
  6. priceFor() must return the price of an order of the given size.
  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 WingPricer class has already been written. It is named WingPricerTest and the source code (i.e., the .java file) is available at:

WingPricerTest.java

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):

  1. Your implementation of the WingPricer class. Do not include the WingPricerTest class.

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.

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 hws under the CS159/hws directory/folder.
  3. Download WingPricerTest.java to the hw1 directory/folder.

Understand the Test Cases

  1. Read and understand the test cases in WingPricerTest.java.
  2. 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

  1. Create a version of the WingPricer 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 WingPricer class and the methods in it.
  3. Check the style of the WingPricer class and make any necessary corrections.

Check WingPricerTest.java

  1. Make sure there are no compile-time errors in WingPricerTest.java. If there are, you probably need to fix the stubbed-out version of WingPricer.java (since there should be no syntax errors in WingPricerTest.java).

Implement and Test the WingPricer Class

  1. Add the “constants”.
  2. Implement the numberOfFullBoxes() method.
  3. Run the WingPricerTest class and make sure that all of the answers returned by the numberOfFullBoxes() method are correct.
  4. Debug numberOfFullBoxes() if necessary.
  5. Implement the numberOfExtras() method.
  6. Run the WingPricerTest class and make sure that all of the answers returned by the numberOfExtras() method are correct.
  7. Debug numberOfExtras() if necessary.
  8. Implement the needAnExtraBox() method.
  9. Run the WingPricerTest class and make sure that all of the answers returned by the needAnExtraBox() method are correct.
  10. Debug needAnExtraBox() if necessary.
  11. Implement the numberOfBoxes() method.
  12. Run the WingPricerTest class and make sure that all of the answers returned by the numberOfBoxes() method are correct.
  13. Debug numberOfBoxes() if necessary.
  14. Implement the priceFor() method.
  15. Run the WingPricerTest class and make sure that all of the answers returned by the priceFor() method are correct.
  16. 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.

  1. What compile-time errors (if any) do you get in WingPricer.java if you make the attributes non-static? Why?
  2. What compile-time errors (if any) do you get in WingPricer.java if you make all of the methods non-static? Why?
  3. What compile-time errors (if any) do you get in WingPricerTest.java if you make the methods in WingPricer.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 numberOfBoxes() after it has you implement numberOfExtraBoxes() and needAnExtraBox()?