CS139
PA5 – BestWraps
Objectives
The following skills are addressed in completing this assignment.
- Writing java code to create an attractive user interface
- Creating and using your own classes
- Using selection structures
- Using repetition structures
- Validating user input
- Using a simple array of objects
- Decomposing a complex problem in a top-down fashion
- Following a "style guide"
- READING AND FOLLOWING DIRECTIONS!!!!!
Deliverables
This assignment requires you to modify and submit a program. You will submit this in 2 stages. The first milestone is due by 11:59 on Thursday, Nov. 21 by 11:59. For the first milestone, you should submit the following java files: StoreRoom.java, Box.java and WrappingPaper.java. You should bundle the three (3) java files into a single zip file and submit via WebCAT.
The completed program must be submitted to WebCAT by 11:59pm on Thursday, December 5. You should bundle the six (6) java files into a single zip file and submit via WebCAT.
Specification
In this assignment, you will design and implement a program that populates a Store Room with wrapping paper of varying sizes and that allows boxes of varying sizes to be wrapped. Your program must be built using the following five classes:
Each piece of wrapping paper is identified by its dimensions (length and width). In order to wrap a box, you must know the dimensions of the box to be wrapped in order to determine which piece of wrapping paper in the store room is the "best" piece of wrapping paper to use. The "best" piece of wrapping paper is the one with the smallest area that is large enough to wrap the box that is presented.
To calculate the size of paper needed, you will need to regularize the box dimensions. That is, the length should be the longest side, the depth should be the shortest side, and the width should the median size (no matter how the user may have entered it). Note: all dimensions are in inches. For the first dimension of the paper, add the width + the depth and multiply the total by 2. Add to this 2 inches. For the other dimension, add the length + two times the depth. You will be looking for the smallest sheet of wrapping paper (measured by area) that will accommodate the dimensions calculated.
You should present a welcome message to the user, followed by a blank line, followed by a menu. The menu will consist of 3 options followed by a prompt (-> ) [note the space after the prompt):
Program Behavior
Your program should begin by printing the following menu:
CS139 Wrapping Paper Storeroom
1. Add paper to storeroom
2. Wrap box
3. Quit
->
In addition to the above, your program must conform to the following requirements:
- The StoreRoom:
- The Storeroom should store the individual pieces of WrappingPaper in an array. The array should store 100 WrappingPaper objects.
- Add paper to the storeroom
- The program will ask the user to enter the dimensions of the box as follows (asking for length first, followed by width):
[blank line here]
Length
Width
- When a piece of WrappingPaper is added to the Storeroom, it should be added to the end of the array. Once a piece of wrapping paper has been successfully added, you should print the following message and return to the opening menu (with the heading):
[blank line here]
Paper added (50x24)
[blank line here]
- If the Storeroom is full (the array has no more slots), you should notify the user that the storeroom is full. The program should pause and wait for the user to press the key. Following this, your program should return to the opening menu (with the heading).
[blank line here]
Unable to add. Warehouse is full.
Press ENTER to continue . . .
[blank line here]
- Wrap box
- The program will ask the user to enter the dimensions of the box as follows:
[blank line here]
Length:
Width:
Depth:
- The program should “regularize” the dimensions of the box. That is, the longest side should be assigned to length, the shortest side to depth, and the median side to width. So, if the user enters 20 for length, 6 for width, and 30 for depth, the program should set the length to 30, the width to 20, and the depth to 6.
- If no suitable piece of WrappingPaper is found, your program should print the following message and wait for the user to press the key. Following this, your program should return to the opening menu (with the heading).
[blank line here]
For the box 10x12x7:
No wrapping paper available.
Press ENTER to continue . . .
[blank line here]
- If a suitable piece of WrappingPaper is found, the print should print the following and wait for the user to press the key. Following this, your program should return to the opening menu (with the heading).
[blank line here]
For the box 10x12x7:
Paper from slot 14: 42x26.
Press ENTER to continue . . .
[blank line here]
- Quit
- If the user chooses to exit, you should print a blank line followed by the word “Goodbye”.
[blank line here]
Goodbye.
[blank line here]
Validation
- All input should be validated. If the user enters something other than a number or a number that is out of range for the menu (less than 1 or greater than 3), the following message should print (do not return to the menu here—keep printing the error message until the user enters a valid value).
[blank line here]
Must be a number between 1 and 3. Please re-enter.
->
- If the user enters something other than a number or a number that is less than 1 for any of the dimensions (for either the wrapping paper or box), the following message should print:
[blank line here]
Must be greater than 0. Please re-enter.
->
Optional
- Optionally, you can remove pieces of WrappingPaper from the Storeroom when they are shipped. This is not as simple as it may seem, since if you remove an object from the array, you will need to close up the space that was taken. However, you can earn a 3-point bonus by implementing this. DO NOT attempt this until you have fully completed the rest of the assignment!! You will get no additional credit if all required functionality is not here!
- You must write the methods as specified in each of the provided java files. You are free to add additional private methods if you find them useful or necessary.
- All I/O (Scanner objects and System.out.print...) should occur in WrapIO.java.
Sample Output
CS139 Wrapping Paper Storeroom
1. Add paper to storeroom
2. Wrap box
3. Quit
-> 1
Length: 50
Width: 24
Paper added (50x24)
CS139 Wrapping Paper Storeroom
1. Add paper to storeroom
2. Wrap box
3. Quit
-> 4
Must be a number between 1 and 3. Please re-enter.
-> 1
Length: -3
Must be greater than 0. Please re-enter.
-> 33
Width: 13
CS139 Wrapping Paper Storeroom
1. Add paper to storeroom
2. Wrap box
3. Quit
-> 2
Box Length: 45
Box Width: 6
Box Depth: 30
For the box 45x30x6:
No wrapping paper available
Press ENTER to continue . . .
CS139 Wrapping Paper Storeroom
1. Add paper to storeroom
2. Wrap box
3. Quit
-> 2
Box Length: 6
Box Width: 10
Box Depth: 12
For the box 12x10x6:
Paper from slot 1: 50x24.
Press ENTER to continue . . .
CS139 Wrapping Paper Storeroom
1. Add paper to storeroom
2. Wrap box
3. Quit
-> 3
Goodbye
Honor Code
This work must conform to the JMU Honor Code and the specific requirements of this class. NO help may be provided by another student to another student. Authorized help is limited to your textbook, the TA’s for any CS139 section, and the professor for your section. You may work with a single Partner as long as you both are working together. If you work as a pair, you should submit one version of your joint program to WebCAT. Divide and conquer is not the way to produce quality code. At the same time, make sure that there is an equal sharing of both roles. It is important that both partners understand what is going on in the program. You may not receive help from any other students in the class or outside of the class.
Grading
- Your program will be evaluated both by its correctness and conformance to the required elements.
- You will achieve a grade of 70 for a program that runs correctly and produces exactly the required output in the required format.
- The remainder (30) will be based on your conformance to the Style and other requirements of the assignment. Review the Style Guide before submitting your program.
- All grades will be based on 100 points.
- You may submit any number of times. The only one I will count is the last one submitted.
- Successfully submitted programs that are late will be graded, then the point penalty assessed for each day late.
- For submissions after:
- Dec 5 - 10 points
- Dec 6 - 20 points
- Dec 7 - 30 points
- Dec 8 - 40 points
- Dec 9 - 50 points
- No submissions accepted after Dec 10.
Hints
- Some of the methods to be written are quite small and simple.
- For the individual methods in Box, WrappingPaper and StoreRoom, do not get confused by other aspects of the program.
- The methods in Box concern only a single box. The methods in WrappingPaper concern only a single piece of WrappingPaper. The methods in StoreRoom deal with operations concerning the collection of WrappingPaper objects stored in the StoreRoom. Thus, the StoreRoom class must deal with adding (and optionally removing) pieces of WrappingPaper, traversing through the array and going to a particular piece of WrappingPaper, etc. These methods will be used by the WrappingStation class.