Documentos de Académico
Documentos de Profesional
Documentos de Cultura
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.
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.
import java.util.Date;
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 processing.org 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:
stroke(0,0,0);fill(255,0,0);ellipse(width/4,height/2,30,30);//blackoutline,redfill
stroke(0,0,0,0);fill(0,0,255);ellipse(width/2,height/2,30,30);//transparentoutline,bluefill
stroke(0,255,0);fill(0,255,0);ellipse(3*width/4,height/2,30,30);//greenoutline,greenfill
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.
- 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.
- Implement outlines for all shapes. Default is to display, rather than inhibit outlines. Outline color
will always be black.
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.
HINTS:
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.
publicstaticvoidmain(String[]args){
HotAirBalloonairbag=newHotAirBalloon(10000);
Locomotiveloco=newLocomotive(5000);
System.out.println(airbag.toString());
System.out.println(loco.toString());
}
}
classVehicle{
Stringmode,fuel;
publicStringtoString(){
return"VehicleMode:"+mode+"Fuel:"+fuel;
}
}
classHotAirBalloonextendsVehicle{
intmaxAltitude;
HotAirBalloon(int_alt){
mode="flight";
fuel="propane";
maxAltitude=_alt;
}
publicStringtoString(){
returntoString()+"MaxAltitude:"+maxAltitude;
}
classLocomotiveextendsVehicle{
inthorsePower;
Locomotive(int_hp){
mode="traversal";
fuel="coal";
horsePower=_hp;
}
publicStringtoString(){
returntoString()+"Horsepower:"+horsePower;
}
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.