![]() |
![]() |
|
home—info—labs—hws—exams
textbook—java.lang docs—java.util docs—archive
- Review/practice:
- construct at 20x30 Rectangle whose NW corner is at 100,200.
- declare a variable which can hold a Rectangle.
- Initialize your variable with a 80x80 Rectangle at 0,0.
- Ask that Rectangle what its X coord of NW corner is.
- call the method setLocation(int,int)
- Again, ask that Rectangle what its X coord of NW corner is.
- Note that we can make several different vars each holding
different Rectangles.
(Draw picture on board; compare to Inspect window.)
New:
- make a test class, class TestRectangle
Note: in a test-method, you figure the answers *first*
Write tests for: grow(int,int)
setLocation(int,int);
translate(int,int)
Tip: have *some* test cases involving zeroes and ones, whenever applicable.
Mindset: you'll get paid $100 if you find an incorrect result!
...er, rather, you won't lose 20pts (or, your job).
- Look up documentation for java.awt.Rectangle.
- For several different methods,
(a) read docs;
(b) call interactively (*after* figuring out the expected answer);
(c) write a test case.
Try: grow(int,int)
contains(int,int)
add(int,int)
union(Rectangle)
1 class RectangleTester {
2
3 public static void main( String[] args ) {
4 java.awt.Rectangle r = new java.awt.Rectangle( 10, 15, 100, 200 );
5 r.grow( 5, 5 );
6 System.out.println( "r's width is now " + r.getWidth() + "; I expected 110." );
7 System.out.println( "r's height is now " + r.getHeight() + "; I expected 210." );
8 System.out.println( "r's NW corner is at "
9 + "(" + r.getX() + "," + r.getY() + ")"
10 + "; I expected (5,10)." );
11 }
12
13 } |
home—info—labs—hws—exams
textbook—java.lang docs—java.util docs—archive
| ©2008, Ian Barland, Radford University Last modified 2008.Sep.12 (Fri) |
Please mail any suggestions (incl. typos, broken links) to ibarland |
![]() |