172 Day 2 (bring envelopes)
Day's goals:
· Class is a data type
· How to create Classes and objects
· Knowing whether you are creating classes or making objects
· Tracing calls
· Creating methods; Calling methods
· Make a test class
Rectangle Hwk Review Plus creating objects and tracing and tester:
A. Question examination
1. Make a class or object?
2. Are we supposed to code a main method?
3. Will we be using "this."?
B. Class diagram
4. What instance variables
5. What behaviors
C. Code class, instance variables and stubs
D. Rectangle method
6. Is it a special method or a normal one?
7. What is returned?
8. Do we put values in the constructor's parameters?
9. What should the parameter variables be named?
E. Code the Getters
F. ToString
a. Do you want a print statement here?
b. Which parts are literals?
c. How to separate?
d. Use @override
G. Show how objects are created and used in bluej panel & see UML
H. Class ex: Code the use of the object – first done go type it
a. Make 2 rectangles
b. Print them
c. Show BLueJ Debug
I. More challenging method
a. tell whether a given x and y are inside the rectangle
b. Tester first (make objects inside the method)
c. Helper – getBottomX; getBottomY – Should we?
d. Class ex: Code it – first done go type it
i. Why not use Rectangle.getBottomX();
J. Show JavaDoc
a. Good Homework Doc comments – Class, Method, @param, @return
K. Invariant
a. Document with @exception
b. use IllegalArgumentException
c. throw new illegalArgumentException("Cannot have any negative values in rectangle");
d. grab it with try/catch
i. pull out values inside exception object
e. Trace with people representing programs
L. Export and package
a. Slide 19 of 172Classes for Exception and Packages
Homework Review Summary:
· Class is a data type – Created a Rectangle type
· How to create Classes and objects - Created Rectangle class and then used it to make objects in ShapeMaker
· Knowing whether you are creating classes or making objects – Problem called for creating a class
· Tracing calls – Bluej trace
· Creating methods; Calling methods – Called rectangle's object methods
· Make a test class – used tester
Review other homework assignment:
· Questions and show one answer
Lab
Code the new Rectangle methods (invariant in constructor and isInside) with tester and with the ShapeMaker. Also add a union method that returns the rectangle containing two rectangles. The method will take in one parameter of a rectangle and return a bigger rectangle that contains this.x, this.y and the other rectangle's .x and .y. and both their bottom right points as well.
Add scanner to ask for the Rectangle's 4 parms when creating.
References
· Powerpoint
· Trace
Practice-It: Self Checks: 8.4, 8.9, 8.7, 8.11, 8.19, 8.20, 8.22, 8.26; Exercises: 8.11, 8.13, (see 8.18 could have helped),
Homework