This assignment must be completed by 10:10 AM on Friday,
5 October,
and uploaded to the Homework 6 moodle page.
You should upload only your
RotatedRectangle.java file along with the
java class used to test it.
All your classes should be in
in the edu.unca.cs.csci202 package and have a proper
@author annotation.
Why?
This is the first of a series of assignments to look at classes, inheritence, and interfaces. In this one we look at the “standard” expectations for classes.
Getting starting
First take a look at a Javadoc-created
description
of a RotatedRectangle class.
You’ll need to click RotatedRectangle to see anything
interesting.
The task
Subtask Zero
Create a project with a
class RotatedRectangle using
the starter
code given below. Be sure to add yourself as one of the authors.
package edu.unca.cs.csci202;
/**
*
* @author J Dean Brock <brock@unca.edu>
* @author Your Name Here <youremail@unca.edu>
*/
public class RotatedRectangle {
private int x ;
private int y ;
private int height ;
private int width ;
private double rotation ;
/**
*
* @return X coordinate of the center of the rectangle
*/
public int getX() {
return x ;
}
/**
*
* @param x New X coordinate for the center of the rectangle
*/
public void setX(int x) {
this.x = x ;
}
/**
*
* @return Y coordinate of the center of the rectangle
*/
public int getY() {
return y ;
}
/**
*
* @param y New Y coordinate for the center of the rectangle
*/
public void setY(int y) {
this.y = y ;
}
/**
*
* @return Height of the rectangle (when rotation is 0)
*/
public int getHeight() {
return height ;
}
/**
*
* @param height New height for the rectangle
*/
public void setHeight(int height) {
this.height = height ;
}
/**
*
* @return Width of the rectangle (when rotation is 0)
*/
public int getWidth() {
return width ;
}
/**
*
* @param width New width for the rectangle
*/
public void setWidth(int width) {
this.width = width ;
}
/**
*
* @return Rotation for the rectangle
*/
public double getRotation() {
return rotation ;
}
/**
*
* @param rotation New rotation for the rectangle
*/
public void setRotation(double rotation) {
this.rotation = rotation ;
}
}
Subtask One
It really makes no sense to have a rectangle with negative height or
width, so modify RotatedRectangle so that the
setHeight and setWidth throw
IllegalArgumentException when they
are called with a negative argument.
Be sure that your program creates an
IllegalArgumentException with a useful message.
Subtask Two
Presently, the RotatedRectangle has only one
constructor, the
no-argument default constructor.
Add the following four constructors to RotatedRectangle.
- Five arguments: x, y, width, height and rotation
- Four arguments: x, y, width and height
- Two arguments: x and y
- No arguments: You really do have to do this in Java
By the way, your life will be easier if you start by defining the
first one and then call the
this constructor for the other three.
When appropriate your constructors should throw
IllegalArgumentException.
Subtask Three
Many people will prefer to give the rotation in degrees rather than
radians. Add a second setRotation method that receives a
single int argument representing an angle in degrees.
This argument is then converted into
radians using the formula (Π/180.0)*degrees.
At this point you should have RotatedRectangle class
that follows
this
augmented description
of a RotatedRectangle class.
Subtask Four
Either generate a JUnit test class for your
RotatedRectangle class or write a
main class called DriverHW6 that tests several
methods of RotatedRectangle.
It would be tedious to test all the methods and constructors, but test at last one constructor and three methods.