We have learned some fundamental concepts about classes and objects in Java. Now let’s look at several examples from the class design perspective.
Practical Case 1
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 ...