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

To print an XML file of the given form

Program plan:

  • In the file Coin.java”, create a class Coin”,
    • Declare necessary variables.
    • Define the constructor.
    • Define the method “getValue()” that gets the coin value.
    • Define the method “getName()” that gets the coin name.
    • Define the method “equals()” that checks for equal object.
    • Define the method that to get the hash code.
  • In the file Purse.java”, create a class Purse”,
    • Declare necessary variables.
    • Define the constructor.
    • Define the method “add()” that adds a coin to the purse.
    • Define the method “getTotal()” that gets the total value of the coins in the purse .
    • Define the method “getCoins()” that returns the coins list.
  • In the file PurseBuilder.java”, create a class PurseBuilder”,
    • Declare necessary instance variables.
    • Define the constructor.
    • Define the method “build()” that builds DOM document for a purse.
    • Define the method “createPurse()” that builds DOM element for a purse.
    • Define the method “createCoin()” that builds DOM element for a coin.
  • In the file PurseParser.java”, import necessary packages, and create a class PurseParser”,
    • Declare necessary instance variables.
    • Define the constructor that construct a parser that can parse a countries XML file.
    • Define the method “parse()” that parse an XML file containing a purse.
  • In the file PurseXMLDemo.java”, import necessary packages, and create a class PurseXMLDemo”,
    • Define the method “main()”,
      • Create an object for “PurseParser”.
      • Get the command-line input in “Purse” object.
      • Create an object for “PurseBuilder”.
      • Call the method “build()” to build DOM document.
      • Call the required methods.
      • Print the output.
  • Create corresponding XML file.

Blurred answer
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