Page 349 - Introduction to Programming with Java: A Problem Solving Approach
P. 349
methods identified in Figure 8.5, but it does not yet say anything about how those members of the Square class are implemented.
The next step is to implement the public methods in the Square class. This implementation appears in Figure 8.7a. The constructor and getArea methods are straightforward and do not need explanation. But notice that the “get” in getArea makes this method look like an accessor that simply retrieves an instance
8.6 Top-Down Design 315
/************************************************************
*
Square.java
Dean & Dean
This class manages squares.
************************************************************/
*
*
*
import java.util.Scanner;
public class Square
{
private int width;
//*********************************************************
public Square(int width)
{
}
Apago PDF Enhancer
this.width = width;
//*********************************************************
public int getArea()
{
}
{
}
// end draw
return this.width * this.width;
//*********************************************************
public void draw()
Scanner stdIn = new Scanner(System.in);
System.out.print("Print with (b)order or (s)olid? ");
if (stdIn.nextLine().charAt(0) == 'b')
{
}
else
{
}
drawSolidSquare();
drawBorderSquare();
Figure 8.7a
Square class: first-cut version—part A