EBK BIG JAVA: EARLY OBJECTS, INTERACTIV
EBK BIG JAVA: EARLY OBJECTS, INTERACTIV
6th Edition
ISBN: 8220102010314
Author: Horstmann
Publisher: YUZU
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
Students have asked these similar questions
List down the strenghts and weaknesses of your team project for Capsim Simulation? Explan.
Capsim Team PowerPoint Presentations - Slide Title: Key LearningsWhat were the key learnings that you discovered as a team through your Capsim simulation?
Write the SQL code that permits to implement the tables: Student and Transcript. NB: Add the constraints on the attributes – keys and other.
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
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