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
Students have asked these similar questions
Answer the question fully and accurately by providing the required files(Java Code, Two output files and written answers to questions 1-3 in a word document)meaning question 1 to 3 also provide correct answers for those questions.(note: this quetion is not graded).
.NET Interactive Solving Sudoku using Grover's Algorithm We will now solve a simple problem using Grover's algorithm, for which we do not necessarily know the solution beforehand. Our problem is a 2x2 binary sudoku, which in our case has two simple rules: •No column may contain the same value twice •No row may contain the same value twice If we assign each square in our sudoku to a variable like so: 1 V V₁ V3 V2 we want our circuit to output a solution to this sudoku. Note that, while this approach of using Grover's algorithm to solve this problem is not practical (you can probably find the solution in your head!), the purpose of this example is to demonstrate the conversion of classical decision problems into oracles for Grover's algorithm. Turning the Problem into a Circuit We want to create an oracle that will help us solve this problem, and we will start by creating a circuit that identifies a correct solution, we simply need to create a classical function on a quantum circuit that…
.NET Interactive Solving Sudoku using Grover's Algorithm We will now solve a simple problem using Grover's algorithm, for which we do not necessarily know the solution beforehand. Our problem is a 2x2 binary sudoku, which in our case has two simple rules: •No column may contain the same value twice •No row may contain the same value twice If we assign each square in our sudoku to a variable like so: 1 V V₁ V3 V2 we want our circuit to output a solution to this sudoku. Note that, while this approach of using Grover's algorithm to solve this problem is not practical (you can probably find the solution in your head!), the purpose of this example is to demonstrate the conversion of classical decision problems into oracles for Grover's algorithm. Turning the Problem into a Circuit We want to create an oracle that will help us solve this problem, and we will start by creating a circuit that identifies a correct solution, we simply need to create a classical function on a quantum circuit that…

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