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

Sub Arrays

Program plan:

Filename: “SubarrayGenerator.java”

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

  • Import the required packages.
  • Define a class “SubarrayGenerator”.
    • Define a method “main()”.
      • Create an array “two”.
      • Call the method “generateSubarrays()” on “two” and print the results.
      • Print the expected sub arrays.
      • Create an array “three”.
      • Call the method “generateSubarrays()” on “three” and print the results.
      • Print the expected sub arrays.
      • Create an array “list”.
      • Call the method “generateSubarrays()” on “list” and print the results.
      • Print the expected sub arrays.
    • Define a method “generateSubarrays()”.
      • Call the method “split()” and return the value.
    • Define a method “cut()”.
      • If “start” is equal to “end”,
        • Return the element of “list” and index “start”.
          • Declare the variables “i” and “j”.
          • Declare a string array “subList” and assign “[” to it.
          • If “start” is less than length of the “list”.
            • Add the element at “start” of the list to “subList”.
          • Iterate a “for” loop.
            • Add “subList”, “,”, “list[i]” and add the result to “subList”.
          • Add “subList”, “,”,”list[end]” and “]” and add the result to “subList”.
          • Return he “subList”.
    • Define a method “paddedCut()”.
      • Declare the variables “i” and “j”.
      • Create a string variable “subList” and assign “[” to it.
      • If “start” is greater than “0”.
        • Add “subList”, “[”, “list[0]” and “]” and add the result to “subList”.
          • Iterate a “for” loop,
            • Add “subList”, “,[”, “list[i]” and “]” and add the result to “subList”.
          • If “start” is equal to 0,
            • Call the method “cut()” to cut the list.
          • Else,
            • Call the method “cut()”.
          • Iterate a “for” loop up to “list.length”.
            • Add “subList”, “,[”, “list[i]” and “]” and add the result to “subList”.
          • Add “subList” and “]” and assign the result to “subList”,
          • Return “subList”.
    • Define a method “split()”.
      • If the “tail” is equal to 0.
        • Call the method “paddedCut()” and return the value.
          • If the “tail” is not equal to “0”,
            • Create a string variable “subList” and assign “[” to it.
            • Iterate a “for” loop up to “j<tail”.
              • Add “subList”, “[”, “sequence[j]” and “],” and add the result to “subList”.
                • Call the method “cut()” and add the result to “subList”.
                • Iterate a “for” loop up to “part<=tail”.
                  • Call the method “paddedCut()” and add its result with “subList”.
                  • Iterate a “for” loop,
                    • Call the method “paddedCut()” and add its result with “subList”.
                • Call the method “split()” and add the result with “subList” and return the value.

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