Menu

(Solved) : Part Various Publications Described Follows Paperpublication Class Following Title String Q31537283 . . .

Part I

Various publications can be described as follows:

 A PaperPublication class with the following: a title (Stringtype), price (double type) and number

of pages (int type).

 A Book is a PaperPublication that in addition has thefollowing: an ISBN (long type), an issue

year (int type), and author(s)name (String type).

 A ChildrenBook is a Book that in addition has the following:minimum age (int type), which

indicates the minimum age that this book is expected for.

 An EducationalBook is a Book that in addition it has thefollowing: edition number (int type) and

speciality field (String type), such as pharmaceutical,engineering, commerce, etc.

 A Journal is a PaperPublication that in addition has thefollowing: issue number (int type) and

speciality field (String type), such as pharmaceutical,engineering, commerce, etc.

 A Magazine is a PaperPublication that in addition has thefollowing: paper quality (enumeration type that can be: High,Normal, or Low), and issuing frequency (enumeration type that canbe:Weekly, Monthly, or Yearly).

Part I:

Draw a UML representation for the above mentioned classeshierarchy. Your representation must also be accurate in terms ofUML representation of the different entities and the relationbetween them. You must use a software to draw your UML diagrams (nohand-writing/drawing is allowed).

Write the implementation of the above mentioned classes usinginheritance and according to the specifications and requirementsgiven below:

 You must have 4 different Java packages for the classes. Thefirst package will include thePaperPublication class. The secondpackage will include the Book, ChildrenBook andEducationalBookclasses. The third package will include the Journal class and thelast package will include the Magazine class.

Comp249/Fall 2018 – Assignment 2 Page 1 of 4

 For each of the classes, you must have at least threeconstructors, a default constructor, a parametrized constructor(which will accept enough parameters to initialize ALL theattributes of the created object from this class) and a copyconstructor. For instance the parametrized constructor of theChildrenBook class must accept 7 parameters to initialize thetitle, the price, the number of pages, the ISBN, the issuing year,the authors name, and the minimum age.

 An object creation using the default constructor must triggerthe default constructor of its ancestor classes, while creationusing parametrized constructors must trigger the parametrizedconstructors of the ancestors.

 For each of the classes, you must include at least thefollowing methods: accessors, mutators,toString() and equals()methods (notice that you are always overriding the last twomethods).

 The toString() method must display clear description andinformation of the object (i.e “ThisChildren Book has 72 pages, andcosts 34$. It is suitable for age 3 and up …..”).

 The equals() method must first check if the passed object (tocompare to) is null and if it is of a different type than thecalling object. The method would clearly return false if any ofthese conditions is true; otherwise the comparison of theattributes are conducted to see if the two objects are actuallyequal. You need to add a comment indicating how effective thesenull verifications inside the method will be in relation toprotecting your program from crashing!

 For all classes, with the exception of the Book class, youmust to use the appropriate access rights, which allows most easeof use/access without compromising security (Do not use mostrestrictive rights unless they make sense!). For the Book class forexample, you are required to use protected access rights.

 When accessing attributes from a base class, you must takefull advantage of the permitted rights. For instance, if you candirectly access an attribute by name from a base class, then youmust do so instead of using a public method from that base class toaccess the attribute.

3. Write a driver program ( that contains the main() method)that would utilize all of your classes. The driver class can be ina separate package or in any of the already existing four packages.In the main() method you must:

 Create various objects from the 6 classes, and display alltheir information using thetoString() method.

 Test the equality of some to the created objects using theequals() method.

 Create an array of 15 PaperPublication objects and fill thatarray with various objects

from the 6 classes (each class must have at least one entry inthat array).

 Trace(search) that array to find the object that has the leastnumber of pages and the one that has the most number of pages.Display all information of these two objects along

with their location (index) in the array.

Comp249/Fall 2018 – Assignment 2 Page 2 of 4

Part II

For the requirements of this part, you need to modify yourimplementation from Part I as follows:

The classes from part I, must now have the most restrictive(secure/protective) access rights to their attributes. Adjust yourimplementation from Part I accordingly, and comment on the decisionabout using restricted access (i.e. what are the tradeoffs).

In the driver program of this part, you need to add to the onefrom part I, another static method (added it above the main()method), called copyBooks. The method will take as imput an arrayof PaperPublication (an array of any size) and returns an array ofPaperPublication. That is to say, the method needs to create anarray of the same length as the passed paramter one, copy all booksfrom the passed array to a new array then return it. Your copy ofthe objects must use the copy constructors of the different listedclasses.

In the driver program, create an array of 12 objects (must haveat least one from each of the classes), then call the copyBooks()method to create a copy of the that array.

Display the contents of both arrays, then add some commentsindicating whether or not the coping is correct. If not; you needto explain why it has not been sucessful or as you mightexpected.

General Guidelines When Writing Programs

 

 

– –

Include the following comments at the top of each class you arewriting.

// —————————————————–// Assignment (include number)// Part: (include Part Number)// Written by: (include your name(s) and student ID(s))// —————————————————–

Use appropriate comments when needed.
Display clear prompts for the user whenever you are expecting theuser to enter data from the keyboard.
All outputs should be displayed with clear messages and in an easyto read format.
End your program with a closing message so that the user knows thatthe program has terminated.

Expert Answer


Answer to Part Various Publications Described Follows Paperpublication Class Following Title String Q31537283 . . .

OR