Big Java, Binder Ready Version: Early Objects
Big Java, Binder Ready Version: Early Objects
6th Edition
ISBN: 9781119056447
Author: Cay S. Horstmann
Publisher: WILEY
Question
Book Icon
Chapter 13, Problem 1PE
Program Plan Intro

Area of a Rectangle

Program plan:

Filename: “Rectangle.java”

This program file is used to define a class “Rectangle”. In the code,

  • Define a class “Rectangle”.
    • Declare class members “width” and “height”.
    • Define a constructor “Rectangle()”.
      • Initialize the “width” and “height”.
    • Define a method “getArea()”.
      • If the “width” is less than or equal to 0,
        • Return “0”.
          • If the “width” is equal to “1”,
            • Return “1*height”.
          • Create the object of class “Rectangle”.
          • Calculate “smallerArea” by recursively calling “getArea”.
          • Return the value of “smallerArea + width + height - 1”

Filename: “RectangleDemo.java”

This program file is used to define a class “RectangleDemo”. In the code,

  • Define a class “RectangleDemo”.
    • Define a method “main()”.
      • Create the object “r1” of class “Rectangle”.
      • Create the object “r2” of class “Rectangle”.
      • Call the method “getArea()” and print the result.
      • Print the expected result.
      • Call the method “getArea()” and print the result.
      • Print the expected result.

Blurred answer

Chapter 13 Solutions

Big Java, Binder Ready Version: Early Objects

Knowledge Booster
Background pattern image
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education