Problem

Write a generic drawRow method having this heading:private void drawRow(int startCol, int...

Write a generic drawRow method having this heading:

private void drawRow(int startCol, int endCol)

startCol and endCol are the column numbers of the left and right borders, respectively. Then modify the Square class’s draw method in Figure 8.7a to draw either a solid square or a solid triangle whose height and width equal the width of the input width of a square container. What about the area now? Is it a redundant value, or is it a legitimate object attribute? Modify the instance variables and the getArea method accordingly. Then drive your modified Square class (call it Square2) with a Square2Driver whose main method looks like this:

public static void main(String[] args){Scanner stdIn = new Scanner(System.in);Square2 square;System.out.print("Enter width of square container: ");square = new Square2(stdIn.nextInt());square.draw();System.out.println("Area = " + square.getArea());} // end main

Sample session:

Enter width of square container: 5Print (s)quare or (t)riangle? t***************Area = 15

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 8
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT