WOD2: Creating a Rectangle class
So far we have created a Circle & Square class. Next we’ll create a Rectangle class.
Rx: <10 min
Av: 10-20 min
Sd: 20-30 min
DNF: 31+ min
Instructions
- Write down your start time on your notecard.
- If you haven’t been following along in class, download the Shapes Project and import it into your workspace. Make sure to rename the project
Shapes_uLogin
.
- Right-click on your Shapes project and go to New > Class to create a
Rectangle
class. Go ahead and check the box for Eclipse to create a main method.
- Add 5 fields to this class:
x
, y
, width
, height
, and color
. Integers are recommended.
- Add 2 constructors:
- Default constructor (no parameters)
- Constructor with 5 parameters (one for each field)
- Add get & set methods for the
width
field.
- Test that your set & get width methods are working in main by:
- Creating a Rectangle variable & initializing it by calling one of the constructors
- Printing out your Rectangle variable’s width value
- Setting the width to a different value.
- Printing the new value by calling your get method.
- Run the program to verify your changes.
- Export your program by right-clicking on your project folder, and selecting
Export > General > Archive File
. Name the file Rectangle_uLogin.zip
.
- Upload the file to the assignment page on canvas
- Write down your stop time on your notecard.