You are on page 1of 6

ITEC 2150 Practice Exam

This portion will account for 45 points of 100 points for Exam1.
The other 55 points will be assessed through a take home
concept test.

Where applicable, use good coding style as we have discussed

and illustrated in class.

Part 1: Definition and Example (10 points)

Consider the following class. Sketch a UML-style class diagram for this class on a piece of paper.
Add your name and submit it to the instructor.

Be sure to allocate a space in your diagram for the class name, fields and methods. Handle public
and private visibility with +/- signs. Static declarations should be underlined.

Here's the class:

import java.util.Date;

public class SodaMachine {

public final static int NUM_BINS = 32;

private Date initialized;

private int serialNumber;
public String[] inventory;

public SodaMachine(int serial, Date d) {

initialized = d;
serialNumber = serial;
inventory = new String[10];

public static void main(String[] args) {

SodaMachine machine = new SodaMachine(127823, new Date());
System.out.println("machine initialized=" + machine.getInitialized());
System.out.println("machine serial number=" + machine.getSerialNumber());

public static int getMaxSerialNumber() {

return Integer.MAX_VALUE;

public String[] getInventory() {

return inventory;

public void setInventory(String[] inventory) {

this.inventory = inventory;

public Date getInitialized() {

return initialized;

public int getSerialNumber() {

return serialNumber;

Submission: Hand in the paper containing your diagram, before leaving.

Part 2: Creating the HexagonalRing Class (30 points)

In class, we created Rectangle, Circle, and Shape classes. Expand this object model to include a
new class named HexagonalRing. You may want to study the Ring class.

A project is included that includes Rectangle, Circle, Ring, HexagonalRing and Shape
(retrieve the zip file from the dropbox where you downloaded this file). Edit the HexagonalRing class
accordingly. The provided project will run as-is, but lacks the tester code for HexagonalRing objects
and lacks the implementation of HexagonalRing. It also lacks two new features: (1) every object
can have a black outline (independent of fill color) and (2) an objects outline can be selectively
disabled (outline on is the default). Once implemented, your sketch should produce output that
looks like the image provided above.

If youre unclear about Processings handling of fill and stroke (outlines), experiment with the
following code in an empty sketch:



Once you've created HexagonalRing, you should uncomment those lines in the leftmost tab (labelled
Exam1_Coding) with the prefix //TODO or delimited by comment blocks with /*TODO */. Your
sketch should create output identical to that provided in the image above.

Your HexagonalRing class must:

- provider a 4-arg constructor that takes x,y, inner side and outer side lengths

- provides a 0-arg constructor that creates a HexagonalRing at x,y=0,0 with inner side=20 and
outer side=30

- provide textual output displaying the HexagonalRings perimeter and area, as demonstrated in the
image above. Be sure to check that your area calculation is correct the value represented above
may not be correct.

Your sketch must:

- Implement outlines for all shapes. Default is to display, rather than inhibit outlines. Outline color
will always be black.

- Allow outlines to be switched off.

- take advantage of inheritance, where ever possible


Are there any statements in the PolygonTester class that illustrate polymorphic behavior? List any
statements from Shapes_Practice_Coding (just the leftmost tab) that illustrate polymorphic
behavior. Please provide the actual statement(s) in your response, not just the line number(s). If
there are none, specify none.

You can solve this problem without being a geometry expert. Its more about OO design than it is
about math. Recall the rogue and shape classes weve discussed in class.
You may want to use the supplied hexagon method in your HexagonalRing class to draw a hexagon.
to It works very similarly to the rect() and ellipse() methods.

The formulas for area and perimeter of a hexagon are (where s is the side length):

Area = (3*Math.sqrt(3.0)*s*s)/2
Perimeter = 6*s

Submission: Provide any .pde files modified. Provide your response to the polymorphism question in
the dropboxs comment field at submission time.

Part 3: Find the Bug (5 points)

Consider the following code:













The author was hoping for the following output:

Vehicle mode:flight Fuel:propane Max Altitude:10000

Vehicle mode:traversal Fuel:coal Horsepower:5000

However, the author is encountering an error at runtime. For reference, the author was hoping to to
take advantage of a capability called dynamic binding, although we didnt refer to it this way in
class. In class, we simply described this as accessing a superclass methods. How can the author
modify the code to get the desired output? Be sure to modify the HotAirBalloon and Locomotive
subclasses to access their superclass toString() method.
The following that is highlighted isnt declared.

Submission: Submit all java source files, with the fix.