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 2PE
Program Plan Intro

Area of a Square

Program plan:

Filename: “Square.java”

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

  • Define a class “Square”.
    • Declare class members “width”.
    • Define a constructor “Square ()”.
      • Initialize the “width”.
    • 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”.
          • Create the object of class “Square”.
          • Calculate “smallerArea” by recursively calling “getArea”.
          • Return the value of “smallerArea + width + height - 1”

Filename: “SquareDemo.java”

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

  • Define a class “SquareDemo”.
    • Define a method “main()”.
      • Create the object “s1” of class “Square”.
      • Create the object “s2” of class “Square”.
      • 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
Find the error, assume data is a string and all variables have been declared. for ch in data:         if ch.isupper:             num_upper = num_upper + 1         if ch.islower:             num_lower = num_lower + 1         if ch.isdigit:             num_digits = num_digits + 1         if ch.isspace:             num_space = num_space + 1
Find the Error: date_string = input('Enter a date in the format mm/dd/yyyy: ') date_list = date_string.split('-') month_num = int(date_list[0]) day = date_list[1] year = date_list[2] month_name = month_list[month_num - 1] long_date = month_name + ' ' + day + ', ' + year print(long_date)
Find the Error:       full_name = input ('Enter your full name: ')       name = split(full_name)       for string in name:         print(string[0].upper(), sep='', end='')         print('.', sep=' ', end='')

Chapter 13 Solutions

Big Java, Binder Ready Version: Early Objects

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