Big Java Late Objects
Big Java Late Objects
2nd Edition
ISBN: 9781119330455
Author: Horstmann
Publisher: WILEY
Question
Book Icon
Chapter 9, Problem 14PP
Program Plan Intro

Implementation of “MySequence”, and “SequenceDemo” class

Program plan:

  • In a file “Sequence .java”,
    • Create a package.
    • Create an interface “Sequence”,
      • Declare the method “next()”.
      • Declare the Boolean method “hasNext()”.
  • In a file “MySequence.java”,
    • Create a package.
    • Create a class “MySequence”,
      • Declare the variable.
      • Initialize the array variable with populations in the cities.
      • Define the method “next()” to determine if the sequence has another value.
      • Define the method “next()”,
        • Initialize the variable.
        • Increment the sequence by “1”.
        • Return the value.
  • In a file “LastDigitDistribution.java”,
    • Create a package.
    • Create a class “LastDigitDistribution”,
      • Declare the array for counter.
      • Define the constructor to set the counter array.
      • Define the method “process()”,
        • Execute loop if the sequence contains another value,
          • Assign the value returned from “next()”.
          • Compute last digit.
          • Increment the last value in the array.
            • Define the method “display()”,
              • Create loop to execute for “10” times,
                • Print the value.
  • In a file “SequenceDemo.java”,
    • Create a package.
    • Create a class “SequenceDemo”,
      • Define the method “main()”
        • Create object for “LastDigitDistribution”.
        • Call the method “process()”.
        • Call the method “display()”.

Blurred answer

Chapter 9 Solutions

Big Java Late 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