We have learned some fundamental concepts about classes and objects in Java. Now let’s look at several examples from the class design perspective.
30. Design Considerations
Ron Dai1
(1)
Seattle, WA, USA
The following is a design of a Rectangle class
. It wants to compute a rectangle’s area, perimeter, and diagonal, given its width and height values as input parameters.
public class Rectangle {
private int width;
private int height;
private int area;
private double diagonal;
private int perimeter;
public Rectangle (int width, int height) {
this.width = width;
this.height = height;
this.area ...
Get Learn Java with Math: Using Fun Projects and Games now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.