Practice writing and calling void
methods that take parameters.
Following coding standards.
Using Checkstyle to check coding standards.
For this activity we will make use of the StdDraw
class developed by Robert Sedgewick and Kevin Wayne at Princeton University. This class provides a set of methods that make it possible to create simple drawings in Java.
You can find the complete documentation online, but today we will only be working with the following methods:
Modifier and Type | Method and Description |
---|---|
static void |
circle(double x, double y, double radius)
Draws a circle of the specified radius, centered at (x, y).
|
static void |
filledCircle(double x, double y, double radius)
Draws a filled circle of the specified radius, centered at (x, y).
|
static void |
rectangle(double x, double y, double halfWidth, double halfHeight)
Draws a rectangle of the specified size, centered at (x, y).
|
static void |
filledRectangle(double x, double y, double halfWidth, double halfHeight)
Draws a filled rectangle of the specified size, centered at (x, y).
|
static void |
line(double x0, double y0, double x1, double y1)
Draws a line segment between (x0, y0) and (x1, y1).
|
DrawDemo.java
in jGRASP. Take a minute to read over the code, then compile and execute it.DrawDemo.java
to place a small filled rectangle in the upper-left corner of the drawing window. Test your modifications.Houses.java
using jGRASP. Take a minute to read over the provided code, then try running it.drawHouse
that satisfies the following requirements:
double
parameters named x
and y
.drawDoor
. YOU SHOULD NOT COPY THE CONTENTS OF drawDoor
INTO drawHouse
!Modify your main
so that in includes three calls to drawHouse
. Houses should be drawn at (.2, .5), (.5, .5) and (.8, .5). The result should look like the following:
Make any necessary modifications to ensure that your finished program conforms to the style guide from Lab3.
Follow the instructions on the Checkstyle lab page to run Checkstyle on Houses.java
. Fix any style issues that are flagged.
In order to complete this lab you need to:
Houses.java
. You can save the image through the file menu of the StdDraw drawing window. The file name should be "houses.jpg".Houses.java
and houses.jpg file through https://autolab.cs.jmu.edu Autolab is configured to run Checkstyle. In order to get full credit, your submission will need to pass all of the formatting tests along with compiling and checking the diff on your output.Acknowledgements: This lab was originally developed by Nathan Sprague.