Practice exam 3
This is a "closed book" examination and you must work entirely on your own. However, you may use the following reference card.

The source code you submit must be entirely your work and must be written entirely during the lab period. The use of any pre-existing code (other than that provided as part of the exam) is prohibited.
You may only use a terminal/shell window, the course IDE and a WWW browser; the only page you may load in the WWW browser is the course submission site (https://autolab.cs.jmu.edu).
Your code need not comply with the course style guidelines and need not include comments. You should not submit any tests.
You should stub-out your classes before you do anything else (i.e., make sure that your classes have all of the required methods, and that each method has the correct signature and returns an appropriately-typed value if necessary).
No limit will be placed on the number of submissions but, obviously, you must complete the exam during the lab period and submissions waste time. Autolab will not provide hints. Your last submission is the one that will be graded.
1. (10 points) Implement a class namedGeometer
that includes the following method. (Your solution must be consistent with the comments describing it.)
/** * Returns true if two Rectangle objects have the same * width and height, even if they have a different x and/or y * (and returns false otherwise). * * @param r One Rectangle object * @param s The other Rectangle object * @return true if r and s have the same width and height */ public static boolean areSimilar(Rectangle r, Rectangle s) { }
2. (15 points) Complete the following
Dress
class. Your implementation must be consistent with the comments.
/** * An encapsulation of a Dress in a retail inventory system */ public class Dress { private int size, style; private String color; /** * Explicit Value Constructor. * * @param style The style of the dress * @param size The size of the dress (between 1 and 22, inclusive) * @param color The color of the dress */ public Dress(int style, int size, String color) { } /** * Returns true if this Dress has the same style, size * and color of the other dress. * * @param other The other Dress */ public boolean equals(Dress other) { } /** * Returns the style of this Dress. */ public int getStyle() { } /** * Returns true if this Dress is a Juniors size. * * Note: Juniors sizes are odd numbers */ public boolean isJuniors() { } }
Dress
class above, complete the following Inventory
class. Your implementation must be consistent with the comments. You may add attributes and/or methods. You may not delete/remove any methods./** * An Inventory object can be used to keep track of the number * of Dress objects of each style that are currently in inventory. * * Notes: * * Styles are numbered consecutively, starting from 0. So, * if there are 7 styles, they will be numbered 0, 1, ..., 6. * * An Inventory object does not differentiate Dress objects * on the basis of color or size. It only keeps track of * the number of Dress objects of each style. * * This class does not perform error-checking on style numbers. * In other words, it assumes that all style numbers are valid. */ public class Inventory { private int[] numberInStock; /** * Explicit Value Constructor. * * Constructs an Inventory object that can keep track * of the given number of Dress styles * * @param numberOfStyles The number of styles */ public Inventory(int numberOfStyles) { } /** * Increase the inventory level (i.e., the number of * dresses "in stock") for the given Dress. * * @param d The Dress that was added to the inventory */ public void add(Dress d) { } /** * Returns the "count" of all dresses with the given style. * * @param style The style of interest */ public int getNumberInStock(int style) { } /** * Decrease the inventory level (i.e., the number of * dresses "in stock") for the given Dress. * * Note: This method checks to make sure that there * is a Dress with the given style in inventory before it * adjusts the inventory level. It returns * true if there is a Dress with the given style in inventory and * false if there is not such a Dress. * * @param d The Dress of interest * @return true if there was a Dress with the given style in inventory */ public boolean remove(Dress d) { } }