Comp 249 -Object-Oriented Programming II Assignment 2  Solved

35.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: zip solution files instantly, after Payment

Securely Powered by: Secure Checkout

Description

5/5 - (3 votes)

Purpose: The purpose of this assignment is to practice class inheritance, and other Object Oriented Programming concepts such as constructors, access rights, method overriding, etc. The assignment would also allow you to practice the notion of package creation. This assignment contains two parts. You need to complete part I to be able to do part II.

 

Part I

 

Various publications can be described as follows:

 

  • A PaperPublication class with the following: price (double type) and number of pages (int type).

 

  • A Book is a PaperPublication that in addition has the following: an ISBN (long type), an issue year (int type), a title (String 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 the following: edition number (int type) and speciality field (String type), such as pharmaceutical, engineering, commerce, etc.

 

  • A Journal is a PaperPublication that in addition has the following: issue number (int type) and speciality field (String type), such as pharmaceutical, engineering, commerce, etc.

 

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

 

 

Part I:

 

  1. Draw a UML representation for the above mentioned classes hierarchy. Your representation must also be accurate in terms of UML representation of the different entities and the relation between them. You must use a software to draw your UML diagrams (no hand-writing/drawing is allowed).

 

  1. Write the implementation of the above mentioned classes using inheritance and according to the specifications and requirements given below:

 

  • You must have 4 different Java packages for the classes. The first package will include the PaperPublication The second package will include the Book, ChildrenBook and EducationalBook classes. The third package will include the Journal class and the last package will include the Magazine class.

 

  • For each of the classes, you must have at least three constructors, a default constructor, a parametrized constructor (which will accept enough parameters to initialize ALL the attributes of the created object from this class) and a copy constructor. For instance the parametrized constructor of the ChildrenBook class must accept 7 parameters to initialize the price, the number of pages, the ISBN, the issuing year, the title, the authors name, and the minimum age.

 

  • An object creation using the default constructor must trigger the default constructor of its ancestor classes, while creation using parametrized constructors must trigger the parametrized constructors of the ancestors.

 

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

 

  • The toString() method must display clear description and information of the object (i.e “This Children Book has 57 pages, and costs 28$. It is suitable for age 4 and up …..”).

 

  • The equals() method must first check if the passed object (to compare to) is null and if it is of a different type than the calling object. The method would clearly return false if any of these conditions is true; otherwise the comparison of the attributes are conducted to see if the two objects are actually equal. You need to add a comment indicating how effective these null verifications inside the method will be in relation to protecting your program from crashing!

 

  • For all classes, with the exception of the Book class, you are required to use the appropriate packages access rights. For the Book class for example, you are required to use protected access rights.

 

  • When accessing attributes from a base class, you must take full advantage of the permitted rights. For instance, if you can directly access an attribute by name from a base class, then you must do so instead of using a public method from that base class to access the attribute.

 

  1. Write a driver program ( that contains the main() method) that would utilize all of your classes. The driver class can be in a 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 all their information using the toString()
    • Test the equality of some to the created objects using the equals()
    • Create an array of 10 PaperPublication objects and fill that array with various objects from the 6 classes (each class must have at least one entry in that array).
    • Trace(search) that array to find the object that is least expensive (has lowest price) and the one that is most expensive. Display all information of these two objects along with their location (index) in the array.

 

Part II 

 

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

 

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

 

  1. In the driver program of this part, you need to add to the one from part I, another static method (added it above the main()method), called copyBooks. The method will take as imput an array of

PaperPublication (an array of any size) and returns an array of PaperPublication. That is to say, the method needs to create an array of the same length as the passed paramter one, copy all books from the passed array to a new array then return it. Your copy of the objects must use the copy constructors of the different listed classes.

 

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

 

  1. Display the contents of both arrays, then add some comments indicating whether or not the coping is correct. If not; you need to explain why it has not been sucessful or as you might expected.

 

General Guidelines When Writing Programs

 

  • Include the following comments at the top of each class you are writing.

// —————————————————–

// Assignment (include number)

// Part: (include Part Number)

// Written by: (include your name(s) and student ID(s))

// —————————————————–

 

  • When commenting your code provide on the top a general and clear explanation of what the piece of code is doing; and within that piece of code if there is any method or any loop specify briefly what is doing. Include comments as needed.
  • Display clear prompts for the user whenever you are expecting the user to enter data from the keyboard.
  • All outputs should be displayed with clear messages and in an easy to read format.
  • End your program with a closing message so that the user knows that the program has terminated.

 

  • A2-vskja0.zip