Exam 2 Practice Lab
Categories:
2 minute read
Part 1: Volume Enumerated Type (20pts)
The following table lists a set of standard US units of volume along with the corresponding conversion to ounces:
Name | Value |
---|---|
OUNCE | 1 |
CUP | 8 |
PINT | 16 |
QUART | 32 |
GALLON | 128 |
Create an enumerated type named Volume
that represents this set of measurements (in this order). Your enum
must contain an instance variable representing the number of ounces associated with each volume. It must also provide two methods, toOunces
and fromOunces
with the following signatures:
public double toOunces(double amount)
- This method must convert from the appropriate volume to ounces. For exampleVolume.CUP.toOunces(2.0)
must return16.0
because there are 16 ounces in 2 cups.public double fromOunces(double ounces)
- This method must convert from ounces to the appropriate volume. For exampleVolume.GALLON.fromOunces(64.0)
must return.5
because 64 ounces is equivalent to .5 gallons.
Your Volume.java
must have a Javadoc comment for the class, but it does not need to provide Javadoc comments for the individual methods. (You are welcome to do so, however.)
Here are the submission tests in case you find it helpful to test locally before submitting:
Submit your completed Volume.java
via Gradescope .
Part 2: Saving and Loading Shapes (30pts)
Download the following files:
- Rectangle.java (finished) - A simple rectangle class that stores width and height as integers.
-
Square.java
(finished) - A subclass of
Rectangle
. ASquare
is-aRectangle
with equal width and height. - ShapeUtils.java (UNFINISHED) - File I/O methods. This is the only file you will need to submit.
- ShapeUtilsTest.java - Submission tests, in case you want to test locally before submitting.
- shapes.txt - Sample text file illustrating the correct file format.
Finish the two unfinished methods in ShapeUtils.java
so that they conform to the provided Javadoc comments.
Submit your completed ShapeUtils.java
via Gradescope .