Exam 2 Practice Lab

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 example Volume.CUP.toOunces(2.0) must return 16.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 example Volume.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:

  1. Rectangle.java (finished) - A simple rectangle class that stores width and height as integers.
  2. Square.java (finished) - A subclass of Rectangle. A Square is-a Rectangle with equal width and height.
  3. ShapeUtils.java (UNFINISHED) - File I/O methods. This is the only file you will need to submit.
  4. ShapeUtilsTest.java - Submission tests, in case you want to test locally before submitting.
  5. 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 .

Last modified April 30, 2022: practice coding exam (a2ce8c8)